UICollectionViewCell gets hidden randomly

前端 未结 3 1202
耶瑟儿~
耶瑟儿~ 2021-01-03 10:36

I have a UIView in which I am adding a UICollectionView to act as a banner view to look like a carousel. The Viewcontroller in which UIView

相关标签:
3条回答
  • 2021-01-03 10:38

    I was calling reloadData from multiple places which caused the system to get confused (may be) especially I have written reloadData in my updateconstraints method and hence for each minor constraint change reloadData was getting called.

    Check all places from where you call reloadData for collectionview if you're experiencing the same problem.

    0 讨论(0)
  • 2021-01-03 10:45

    Same problem.

    Here's my situation:

    My collection view has a custom layout. I use the default flow layout without any problem.

    When I use my custom layout, whose cell width is a half screen width. When I scroll to the 5th cell, all cells became hidden without reason.

    Finally I found out that when I set cell's size correctly in the layout class of the storyboard, the problem is resolved.

    Hope this helps.

    0 讨论(0)
  • 2021-01-03 10:56

    I've encountered the same problem.

    After

    • checking if the UICollectionView reloadData was called in some thread other than the MainThread
    • checking if there is any cases about multi-calling reloadData or updateconstraints

    without solving my problem, I realized that in some occasions CGSizeZero was returned for collectionView:layout:sizeForItemAtIndexPath:.

    When avoiding the CGSizeZero result, everything works well.

    0 讨论(0)
提交回复
热议问题