CollectionView indexPath.row 不正确? 在 TableViewCell 内

问题描述

我有一个我想要 indexPath.row 的集合视图。但是,每当我尝试打印/显示 indexPath.row 编号时,它都会关闭。这是一个水平集合视图,所以当我尝试向右翻页时,它从:0、2、3、4、5 开始,向后跳转到 5、3、2、1、1、1。每次都不一样。

当前 collectionView 位于 tableViewCell 内。数据正在从 Firebase 数据库加载。

    func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int {
        return userList.count
    }

    func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell",for: indexPath) as! FeedCollectionViewCell
        
        
        pageController.currentPage = indexPath.row
        pageController.numberOfPages = userList.count
        
        
        return cell
    }

解决方法

在故事板中将预取启用设置为 false 有效。