gpt4 book ai didi

ios - swift 。按 n 个元素加载 collectionView

转载 作者:行者123 更新时间:2023-11-28 15:16:46 26 4
gpt4 key购买 nike

我对 iOS 开发和 Swift 还很陌生。我有一个从数组中填充图像的 UICollectionView。我的想法是最初加载 10 张图像,让用户滚动到 collectionView 的底部,然后通过按下“更多”按钮或自动加载阵列中的下 10 张图像。你能建议最好的方法吗?我的代码是:

self.searches.insert(results, at: 0)
override func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//1
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,
for: indexPath) as! CatPhotoCell
// this methods takes one photo from searches array
let flickrPhoto = photoForIndexPath(indexPath: indexPath)

cell.imageView.image = flickrPhoto.thumbnail
cell.cat_name.text = flickrPhoto.title

return cell
}

private extension CatsPhotosCollectionViewController {
func photoForIndexPath(indexPath: IndexPath) -> FlickrPhoto {
return searches[(indexPath as NSIndexPath).section].searchResults[(indexPath as IndexPath).row]
}
}

最佳答案

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView){
//这里是第2步
}

1.初始设置数组个数为10。

2.在上面的函数中增加你想要的数组数量并重新加载 collectionView。

关于ios - swift 。按 n 个元素加载 collectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46716226/

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