gpt4 book ai didi

ios - 按需滚动不断调用

转载 作者:行者123 更新时间:2023-11-30 11:24:09 25 4
gpt4 key购买 nike

我正在尝试实现按需滚动调用。直到我滚动到屏幕底部,它才不会调用 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()
}
}
})
}

最佳答案

使用此方法。这肯定会起作用

func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
//Bottom Refresh
if ((scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height) {
if !isWating {
isWating = true
self.doPaging()
}
}
}

关于ios - 按需滚动不断调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50940539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com