我有两个用例。 首先,我想在表格视图中显示从algolia服务器获取的结果。每当我向下滚动到末尾时,都应发送另一次提取以获取新数据。
第二,我有另一个表视图,其中包含不同的部分/类别。每当我单击特定部分时,我只想从algolia加载对象的相应“部分”。当前最大对象数应该为50。但是在这里,我不想一次加载50个对象。应该根据我的表格视图的滚动来加载它们。
我有以下代码来进行“懒惰获取”
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if (challengeArray.count > (10 * i)) {
PAGINATION = PAGINATION + 1
i = i + 1
}
else {
return
}
// if last row of the table view is reached, load the next items
if indexPath.row == challengeArray.count - 1 {
algoliaSearch.fetchChallengeInformationBySearchValue(completionHandler: { (challengeArray) in
// if there is no data, we can return from the function
if (challengeArray.count == 0) {
return
}
for challengeObject in challengeArray {
let results = self.challengeArray.filter { $0.id == challengeObject.id}
if (results.count == 0) {
self.challengeArray.append(challengeObject)
}
}
self.mainCollectionView?.reloadData()
}, searchValue: "", page: PAGINATION)
}
}
我正在尝试使用PAGINATION的值,每当加载特定数量(10)的对象时,该值就会增加,然后向下滚动至末尾以获取下一个10个对象。
请问有人可以帮我两个用例吗?