`
square10
  • 浏览: 3509 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

static cell 与 dynamic cell 混合使用

 
阅读更多

关于静态cell与动态cell的混合使用,google一下便会有很多相关文章,这里也是看过一些前辈的经验(已经忘记具体是从哪篇文章得到的帮助)之后自己做的笔记。

在某些界面中static cell与dynamic cell混合使用会事半功倍,比如手机上的Wi-Fi功能等,效果图如下:

1.png

Wi-Fi界面的第一组与第三组的行数都是固定的,且布局并不相同,类似这样的布局使用static cell很快就可以完成,然而第二组却需要使用dynamic cell。这时候就会用到静态cell与动态cell混合使用的情况。

首先,在Storyboard中添加一个UITableViewController,设置为Static cell,并设置好第一组与第三组的内容,第二组需要设置一个空的Cell,如图:

2.png

然后,给第二组的空白Cell设置identifier值,如图:

3.png

然后,第二组需要自定义cell,这里使用XIB来完成,如图:

4.png

接下来需要用代码注册Nib,如下:

1
2
let nib = UINib(nibName: "WiFiTableViewCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "WiFiTableViewCell")

最后,为了让 static cell 与 dynamic cell 能够混合使用,需要实现TableView的代理,代码如下:

  // 以下代理方法必须实现
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  if indexPath.section == 1 {
    let cell = tableView.dequeueReusableCellWithIdentifier("WiFiTableViewCell") as? WiFiTableViewCell
    return cell!
  }
  return super.tableView(tableView, cellForRowAtIndexPath: indexPath)
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  if section == 1 {
    return 10 //这里返回第二组的行数
  }
  return super.tableView(tableView, numberOfRowsInSection: section)
}

override func tableView(tableView: UITableView, indentationLevelForRowAtIndexPath indexPath: NSIndexPath) -> Int {
  if indexPath.section == 1 {
    return super.tableView(tableView, indentationLevelForRowAtIndexPath: NSIndexPath(forRow: 0, inSection: 1))
  }
  return super.tableView(tableView, indentationLevelForRowAtIndexPath: indexPath)
}

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
  if indexPath.section == 1 {
    return 44
  }
  return super.tableView(tableView, heightForRowAtIndexPath: indexPath)
}

值得注意的是:

  • 在storyboard中需要给第二组设置一行空的Cell,并设置identifier值。

  • 在代码中也需要注册Cell

  • 上面提到的代理方法必须实现

最后,本文主要是记录关于 static cell 与 dynamic cell 的混合使用,因此很多细节问题并没有处理,更多关于static cell另外的一些使用,可以点击这里【更优雅地使用Static Cell】

【Demo下载】

分享到:
评论

相关推荐

    5-RNN-02_RNN基本api

    tf.nn.rnn_cell # 定义rnn 细胞核相关的信息的 tf.nn.rnn_cell_impl # 定义rnn细胞核具体是如何实现的 tf.nn.dynamic_rnn() # 单向动态rnn。 tf.nn.bidirectional_dynamic_rnn() # 双向动态rnn tf.nn.static_rnn() #...

    Cell counting for in vivo flow cytometry signals with baseline drift

    Previous methods, i.e., the dynamic peak picking method, counted cells by setting a static threshold without considering the baseline drift, leading to an inaccurate cell quantification. Here,

    iOS.Recipes(第1版)

    Place Static Content in a Zoomable Scroll View Build a Carousel Paging Scroll View Graphics Recipes Draw Gradient Filled Bezier Paths Create Dynamic Images With Multiple Animations Make Composited ...

    Integrated SRAM compiler with clamping diode to reduce leakage and dynamic power in nano-CMOS process

    An integrated static random access memory (SRAM) compiler is proposed to reduce both leakage and dynamic power at circuit and architectural level. Based on source biasing scheme, an extra clamping ...

    sciter-sdk-4.0.3.5348

    [richtext] + table editing commands: insert/delete row/column, merge cell range, split spanned cell. [gtk] far east languages/fonts rendering. [context menus] fix of getting focus back, see : ...

    EhLib 8.0 Build 8.0.023 Pro Edition FullSource for D7-XE8

    specify macros for current page, current date, current time and/or static text. Automatically print/preview multiselected area of TDBGridEh if it area is not empty. Ability to print/preview ...

    EhLib 6.3 Build 6.3.176 Russian version. Full source included.

    specify macros for current page, current date, current time and/or static text. Automatically print/preview multiselected area of TDBGridEh if it area is not empty. Ability to print/preview ...

    ehlib_vcl_src_9_3.26

    specify macros for current page, current date, current time and/or static text. Automatically print/preview multiselected area of TDBGridEh if it area is not empty. Ability to print/preview ...

    EhLib 9.1.024

    specify macros for current page, current date, current time and/or static text. Automatically print/preview multiselected area of TDBGridEh if it area is not empty. Ability to print/preview ...

    EhLib5.0.13 最新的ehlib源码

    specify macros for current page, current date, current time and/or static text. Automatically print/preview multiselected area of TDBGridEh if it area is not empty. Ability to print/preview ...

    Teach Yourself Electricity & Electronics

    tap rectifier 387 The bridge rectifier 387 The voltage doubler 389...Static current amplification 405 Dynamic current amplification 406 Overdrive 406 Gain versus frequency 407 Common...

    VB.NET Developer's Guide(4574).pdf

    Dynamic Arrays 191 Functions 192 Object Oriented Programming 196 Inheritance 196 Polymorphism 197 Encapsulation 197 Classes 198 Adding Properties 198 Adding Methods 200 System.Object 201 ...

    VB编程资源大全(英文源码 控制)

    dynlistmnu.zip While trying to come up with a Dynamic menu in VB, I decided that VBs menu object was just too much of a pain to work with This project contains a form to mimic the functionality ...

    Springer Press- High performance Packet Switching Architectures(2007)

    3.3.3 The Simple-batch Static Schedule ................................................ 73 3.4 An Interesting Application: Optical Networks ........................................ 74 3.5 Throughput ...

Global site tag (gtag.js) - Google Analytics