【发布时间】:2019-02-03 17:06:59
【问题描述】:
我一直在处理 tableview 并陷入以下问题。
据我了解,willDisplayCell 委托方法应该允许我访问当前的单元格设计。
我的问题是:它无法正常工作。尝试显示 80 个单元格时,该委托函数仅运行五次。不管这个函数以外的任何东西,在委托函数中写一行代码就可以很好地工作。
这是我的代码:
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row == comment_arr.count - 1 {
print("end")
// (1)self.comment_height.constant = self.comment_table.contentSize.height + 30
}
// (2)self.comment_height.constant = self.comment_table.contentSize.height + 30
}
如果 (1) 行存在,则它不起作用。但是如果存在 (2) 行,则效果很好。
如何让它工作?
【问题讨论】:
-
尝试另一种方法来检测到达 tableview 的结尾。我不建议使用“willDisplayCell”,即使它对你有用,但出于多种原因..检查这个stackoverflow.com/questions/39015228/…跨度>
-
print("end")是否打印过任何内容?如果不是,您的 if 语句中的逻辑可能是问题所在。
标签: ios swift xcode uitableview delegates