[英]Scrolling to bottom of a section in tableView
I am trying to write a function that scrolls to the bottom cell of a given section in my tableView, I'm calling this function after my tableView.reloadData()
function but it is not scrolling, any ideas why?我正在尝试编写一个 function 滚动到我的 tableView 中给定部分的底部单元格,我在tableView.reloadData()
ZC1C425268E68385D1AB5074 之后调用这个 function
func scrollToBottom(section: Int){
DispatchQueue.main.async {
let indexPath = IndexPath(row: self.session[section].count - 1, section: section)
self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
}
}
You don't need put code in DispatchQueue.main
because it already run on main thread.您不需要将代码放在DispatchQueue.main
中,因为它已经在主线程上运行。
Try this尝试这个
func scrollToBottom(section: Int){
let indexPath = IndexPath(row: self.session[section].count - 1, section: section)
self.tableView.scrollToRow(at: indexPath, at: .top, animated: true)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.