Ios uitableview willdisplaycell委托很奇怪
我一直在围绕tableview工作,并在以下问题上陷入困境 据我所知,willDisplayCell委托方法应该允许我访问当前的单元格设计 我的问题是:它不能正常工作。当尝试显示80个单元格时,该委托函数仅运行五次。不管这个函数以外的任何东西,在委托函数中编写一行代码都可以使它工作良好 这是我的密码:Ios uitableview willdisplaycell委托很奇怪,ios,swift,xcode,uitableview,delegates,Ios,Swift,Xcode,Uitableview,Delegates,我一直在围绕tableview工作,并在以下问题上陷入困境 据我所知,willDisplayCell委托方法应该允许我访问当前的单元格设计 我的问题是:它不能正常工作。当尝试显示80个单元格时,该委托函数仅运行五次。不管这个函数以外的任何东西,在委托函数中编写一行代码都可以使它工作良好 这是我的密码: func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: In
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(_ tableView: UITableView,
heightForRowAt indexPath: IndexPath) -> CGFloat
在willDisplayCell之前调用
本主题已在此处详细介绍:
首先获取节中的行数。然后找到最后一项
let totalRow = tableView.numberOfRows(inSection: indexPath.section)
if(indexPath.row == totalRow - 1)
{
print("end")
return
}
尝试另一种方法来检测是否到达tableview的末尾。。我不建议使用willDisplayCell,尽管它可以与您一起使用,但原因很多。。检查这个printend是否打印过任何东西?如果不是,你的If语句中的逻辑可能就是问题所在。好的,你的回答很有帮助,我在这里解决了这个问题