【发布时间】:2018-03-14 18:33:27
【问题描述】:
我尝试了很多方法来解决这个问题,但我做不到。我的tableView 在加载更多数据后会跳转。我在willDisplay调用下载方法:
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastObject = objects.count - 1
if indexPath.row == lastObject {
page = page + 1
getObjects(page: page)
}
}
并在此处插入行:
func getObjects(page: Int) {
RequestManager.sharedInstance.getObjects(page: page, success: { objects in
DispatchQueue.main.async(execute: {
self.objects = self.objects + objects
self.tableView.beginUpdates()
var indexPaths = [IndexPath]()
for i in 0...objects.count - 1 {
indexPaths.append(IndexPath(row: i, section: 0))
}
self.tableView.insertRows(at: indexPaths, with: .bottom)
self.tableView.endUpdates()
});
})
}
那我做错了什么?为什么tableView插入新行后会跳转?
【问题讨论】:
标签: ios swift uitableview