ios - 使用 dequeueReusableCellWithIdentifier :forIndexPath:? 时的新单元格或现有单元格

标签 ios uitableview swift

拥有一个UITableViewController并使用:

  override func tableView(tableView: UITableView, cellForRowAtIndexPath 
          indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell
    return cell
 }

使用 dequeueReusableCellWithIdentifier:forIndexPath:'' 而不是 dequeueReusableCellWithIdentifier`` 我如何确定一个单元格是新单元格还是重复使用的单元格?

最佳答案

创建您自己的自定义单元类以用于重用标识符。然后,在该单元格内,实现 awakeFromNib 并对单元格进行更改。当您的单元格从其 NIB 文件加载时,这只会被调用一次。

可以在 prepareForReuse 中进行重用单元格时需要进行的任何其他更改。

关于ios - 使用 dequeueReusableCellWithIdentifier :forIndexPath:? 时的新单元格或现有单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29845151/

相关文章:

iphone - iOS iPhone 手指绘画类应用程序,是否有内置 Canvas 或开源项目可以帮助我入门?

uitableview - 使用swift3在tableview中搜索栏和部分

ios - Swift 中的 NSDecimalRound

swift - UICollectionView 和取消选择单元格不起作用。一旦被选择。这里有什么错误?

ios - watch app在后台能收到后台信息吗?

ios - UISlider:更改了高度,但最大值闪烁

ios - 在Swift 3中使用.droplast()删除空的小数

ios - 使用委托(delegate)显示/隐藏 tableview 单元格

objective-c - 弹出窗口和桌面 View 透明

ios - 以交互方式关闭模态视图 Controller 时出现故障