gpt4 book ai didi

ios - 最后一行未调用 prefetchRowsAt

转载 作者:行者123 更新时间:2023-11-29 05:08:46 25 4
gpt4 key购买 nike

我在 UITableViewDataSourcePrefetching 实现中遇到一个问题。

我在云中总共有 62 条记录,我正在调用 API,该 API 每页返回 15 条记录。

我还实现了 prefetchRowsAt 方法,该方法部分对我来说效果很好。

问题是上述方法不会返回它将要加载的所有索引路径,因此您可以从下面的日志中看到它最多仅达到 53 条,在我的 TableView 中它仅显示 60 条记录。

Indexpaths to fetch : [[3, 51], [3, 42], [3, 52], [3, 41], [3, 53], [3, 40], [3, 54], [3, 39], [3, 55], [3, 38], [3, 56], [3, 37], [3, 57], [3, 36], [3, 58], [3, 35], [3, 59], [3, 34], [3, 60], [3, 33]]
Indexpaths to fetch : [[3, 51], [3, 50], [3, 49], [3, 48], [3, 47], [3, 46], [3, 45], [3, 44], [3, 43]]
Indexpaths to fetch : [[3, 52]]
Indexpaths to fetch : [[3, 53]]

这是我的方法实现

extension MyViewController:UITableViewDataSourcePrefetching{
func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
#if DEBUG
print("Indexpaths to fetch : \(indexPaths)")
#endif

if indexPaths.contains(where: isLoadingCell) {
self.loadFurthersSessionNotification?()
}
}
}

private extension MyViewController {
func isLoadingCell(for indexPath: IndexPath) -> Bool {
if indexPath.section != 3{
return false
}
return (indexPath.row - 1) >= self.aryCloudObjects.count
}
}

任何帮助将不胜感激。

谢谢

最佳答案

您所看到的行为并没有什么意外。无法保证将为表中的每一行调用 prefetchRowsAt

来自documentation :

Table views do not call this method for cells they require immediately, so your data source object must also be able to fetch the data itself.

预取允许您准备显示行,但如果在调用 cellForRowAt: 时尚未预取数据,那么您需要在此时获取数据。

关于ios - 最后一行未调用 prefetchRowsAt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59889734/

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