【发布时间】:2018-06-21 11:39:04
【问题描述】:
我正在尝试实现按需滚动调用。在我滚动到屏幕底部之前,它从不调用 doPaging() 方法,这很好,然后下载另一批数据集(另外 20 个项目)。但是,当它第一次到达屏幕底部并一直调用甚至小滚动到底部时。
我想知道我在以下实现中缺少什么。
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
{
if indexPath.row == self.products.count - 1 && !isWating {
isWating = true
self.pageNumber += 1
self.doPaging()
}
}
func doPaging()
{
fetchProducts(page: pageNumber , completion: { success in
if let products = success as? Products
{
// keeps calling
DispatchQueue.main.async {
self.products.append(contentsOf:products)
self.isWating = false;
self.productTableView.reloadData()
}
}
})
}
【问题讨论】:
-
willDisplay不得有副作用。如果需要,请调整单元格的显示,而不是其他任何东西。 -
能否详细说明?
-
willDisplay方法只有一个目的。来自文档:“表格视图在使用单元格绘制行之前将此消息发送给其委托,从而允许委托在显示单元格对象之前对其进行自定义。”。不要将它用于其他任何事情(例如修改表格视图的数据源或重新加载表格)。 -
我没有看到 products.count 和 pageNumber 之间的关系。
-
@rmaddy,那么为此需要使用哪个委托方法?
标签: ios swift uitableview pagination