【发布时间】:2017-10-13 17:38:17
【问题描述】:
我对 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]
}
}
【问题讨论】:
-
分页是您要查找的单词。
willDisplayCellForItemAtIndexPath如果显示最后一个单元格或倒数第 5 个单元格,请加载更多.. 依此类推..
标签: ios swift uicollectionview