我有一个UITableView
,我正在尝试将36行加载到其中,然后滚动到最后一个单元格。
我尝试了以下方法:
func reloadData(){
chatroomTableView.reloadData()
chatroomTableView.scrollToBottom(true)
}
extension UITableView {
func scrollToBottom(animated: Bool = true) {
let sections = self.numberOfSections
let rows = self.numberOfRowsInSection(sections - 1)
if (rows > 0){
self.scrollToRowAtIndexPath(NSIndexPath(forRow: rows - 1, inSection: sections - 1), atScrollPosition: .Bottom, animated: true)
}
}
}
但它只能滚动一半。
scrollToBottom
函数时,rows
和sections
是否具有预期值? - rmaddyscrollToBottom
的调用包装在dispatch_async
或者dispatch_after
中。 - rmaddy