Why does UICollectionView log an error when the cells are fullscreen?

后端 未结 10 1341
悲&欢浪女
悲&欢浪女 2020-12-08 04:06

I have a UICollectionViewController using a UICollectionViewFlowLayout where my itemSize is the size of the UICollectionView

10条回答
  •  隐瞒了意图╮
    2020-12-08 04:38

    I had similar issue.

    After load cell which is full width and some height of screen. on some condition I changed the height of cell then I was getting the same error

    to fix this

    I used

       func updateHeightPerRatio(with image:UIImage) {
        let ratio = collectionView.bounds.width / image.size.width
        constHeightCollectionView .constant =  ceil(image.size.height * ratio)
        collectionView.reloadData()
        collectionView.performBatchUpdates({
            collectionView.layoutIfNeeded()
        }) { (completed) in
            self.collectionView.reloadData()
            self.layoutIfNeeded()
        }
    }
    

    Solution is reload data then perform batchupdate with that collection view re -calculate the frames . after that reload collectionview again it will apply calculated frames to cell

    And now there is no log for issue now.

    Hope it is helpful

提交回复
热议问题