Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift-如何获取节的indexath.row或类似内容_Swift_Uicollectionview - Fatal编程技术网

Swift-如何获取节的indexath.row或类似内容

Swift-如何获取节的indexath.row或类似内容,swift,uicollectionview,Swift,Uicollectionview,我有一个UICollectionView,有两个不同数据的部分。当用户在一个分区中滚动20个单元格时,我试图在该分区中加载更多数据 例如: 第0节和第1节都有20个单元格 当我滚动浏览第0节中的所有20个单元格时,它应该会将更多数据加载到该节中,并以第0节中的40个单元格和第1节中的20个单元格结束 这就是我所拥有的,但它没有按预期工作: func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICol

我有一个
UICollectionView
,有两个不同数据的部分。当用户在一个分区中滚动20个单元格时,我试图在该分区中加载更多数据

例如:

第0节和第1节都有20个单元格

当我滚动浏览第0节中的所有20个单元格时,它应该会将更多数据加载到该节中,并以第0节中的40个单元格和第1节中的20个单元格结束

这就是我所拥有的,但它没有按预期工作:

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        switch indexPath.section {
        case 0:
            if indexPath.row == popularMovies.count {
                print("Section 0, Row \(indexPath.row) - Loading more popular movies...")
            }
            break
        case 1:
            if indexPath.row == nowPlayingMovies.count {
                print("Section 1, Row \(indexPath.row) - Loading more now streaming movies...")
            }
            break
        default: break
        }
    }

第1节第19行-正在加载更多流媒体电影 查看
UICollectionViewDataSourcePrefetching
,除了为即将滚动到visibible区域的单元格预加载图像外,还可以轻松使用此选项在滚动时加载更多数据

例如:

extension MoviesViewController: UICollectionViewDataSourcePrefetching {
    func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
        let maxItem = indexPaths.map { $0.item }.max() ?? 0
        if maxItem >= self.popularMovies.count - 3 {
            // load new movies
        }
    }
}
extension MoviesViewController: UICollectionViewDataSourcePrefetching {
    func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
        let maxItem = indexPaths.map { $0.item }.max() ?? 0
        if maxItem >= self.popularMovies.count - 3 {
            // load new movies
        }
    }
}