微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CollectionView indexPath.row 不正确? 在 TableViewCell 内

如何解决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 有效。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。