我使用了以下两种方法,它们都可以工作,但是我提到了这个问题。
扩展 UITableView {
func scrollToBottom() {
let sections = numberOfSections-1
if sections >= 0 {
let rows = numberOfRows(inSection: sections)-1
if rows >= 0 {
let indexPath = IndexPath(row: rows, section: sections)
DispatchQueue.main.async { [weak self] in
self?.scrollToRow(at: indexPath, at: .bottom, animated: true)
}
}
}
}
func moveToLastComment() {
if self.contentSize.height > self.frame.height {
let lastSectionIndex = self.numberOfSections - 1
let lastRowIndex = self.numberOfRows(inSection: lastSectionIndex) - 1
let pathToLastRow = NSIndexPath(row: lastRowIndex, section: lastSectionIndex)[enter image description here][1]
self.scrollToRow(at: pathToLastRow as IndexPath, at: UITableViewScrollPosition.bottom, animated: true)
}
}
}
Best Answer-推荐答案 strong>
使用这个方法
self.tableView.setContentOffset(CGPoint(x: 0, y: CGFLOAT_MAX), animated: true)
关于ios - tableView 滚动到底部不显示最后一部分,必须手动滚动,有人知道吗?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/43842263/
|