【问题标题】:Swift. Load collectionView by n elements迅速。按 n 个元素加载 collectionView
【发布时间】: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


【解决方案1】:

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView){ //step 2 here }

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

2.在上述函数中任意增加数组计数并重新加载collectionView。

【讨论】:

  • 您的意思是作为 collectionView 来源的数组吗?
猜你喜欢
  • 2019-01-13
  • 1970-01-01
  • 2021-10-13
  • 1970-01-01
  • 1970-01-01
  • 2017-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多