[英]How to load tableView from the bottom
I receive data from the server and when they come to me the table is updated, how to make sure that when the data came the table would creep down to the bottom? 我从服务器接收数据,当他们来找我时,表格会更新,如何确保数据传输时表格会下降到底部?
tableView.scrollToBottom(animated: true)
don't working 不工作
tableView has no method scrollToBottom, I think you should add this method in the extension of UITableView tableView没有方法scrollToBottom,我认为你应该在UITableView的扩展中添加这个方法
Example : 示例 :
import UIKit
extension UITableView {
func scrollToBottom(animated: Bool) {
let y = contentSize.height - frame.size.height
setContentOffset(CGPoint(x: 0, y: (y<0) ? 0 : y), animated: animated)
}
}
You can use tableView.scrollToRow(at:at:animated:)
. 您可以使用
tableView.scrollToRow(at:at:animated:)
。 For example, let's assume you have an array of string that are show in the table view: 例如,假设您有一个在表视图中显示的字符串数组:
var items = ["1", "2", "3"]
func scrollToBottom() {
let indexPathToReach = IndexPath(row: items.count - 1, section: 0)
tableView.scrollToRow(at: indexPathToReach, at: .bottom, animated: true)
}
reloadData()
method) or insert cells (call insertRows(at:with:)
method) in main thread. reloadData()
方法)或在主线程中插入单元格(调用insertRows(at:with:)
方法)。 scrollToRow(at:at:animated:)
method) in main thread. scrollToRow(at:at:animated:)
方法)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.