美文网首页
iOS UITableView滚到最底部的坑

iOS UITableView滚到最底部的坑

作者: 神秘嘉宾yzj | 来源:发表于2022-08-11 11:31 被阅读0次

// 获取到最后一个cell的index
let indexPath = IndexPath(row: row - 1, section: self.messageList.count - 1)
tableView.scrollToRow(at: indexPath, at: .bottom, animated: false)

可能会有部分偏差

另一个方法说是计算高度,然后设置contentOffset,这个尝试过,但是业务场景会有限制

tableView.scrollToRow(at: indexPath, at: .bottom, animated: false)此方法满足,但是会有坑

最后解决:最后一个cell高度是动态的话造成table的contentSize不准确

在scrollToRow的方法之前 刷新执行刷新最后一行操作:
self.messageTable.reloadRows(at: [indexPath], with: .bottom)
tableView.scrollToRow(at: indexPath, at: .bottom, animated: false)

相关文章

网友评论

      本文标题:iOS UITableView滚到最底部的坑

      本文链接:https://www.haomeiwen.com/subject/olgzwrtx.html