ios - tableView 滚动到底部不显示最后一部分,必须手动滚动,有人知道吗?
<p><p>我使用了以下两种方法,它们都可以工作,但是我提到了这个问题。</p>
<p>扩展 UITableView {</p>
<pre><code>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 { 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)
self.scrollToRow(at: pathToLastRow as IndexPath, at: UITableViewScrollPosition.bottom, animated: true)
}
}
</code></pre>
<p>}</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用这个方法</p>
<pre><code> self.tableView.setContentOffset(CGPoint(x: 0, y: CGFLOAT_MAX), animated: true)
</code></pre></p>
<p style="font-size: 20px;">关于ios - tableView 滚动到底部不显示最后一部分,必须手动滚动,有人知道吗?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/43842263/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/43842263/
</a>
</p>
页:
[1]