anoop4real anoop4real - 1 year ago 177
iOS Question

UICollectionViewCell gets hidden randomly

I have a UIView in which I am adding a collection view to act as a banner view to look like a carousel. The Viewcontroller in which UIView is present, is part of pageviewcontroller.

PageVC --> UIViewController --> UIView --> UICollectionView.

Each VC has its own banner, so when the page is swiped, I reload the collectionView with the respective data and I am able to see it. Now if visit a page which I already visited, the collectionview cell disappears. The collectionview is visible but the cell is somehow hidden.

The collectionview cell is a customcell and I am not using any custom layout, I am using the default flow layout. This is working fine in iOS8 devices.

Below is the debugger output,
When cell is visible:

CollectionViewCell: 0x7f9db8d9ffa0; baseClass = UICollectionViewCell; frame = (209 3.5; 209 96); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x7f9dbb5dde60>>

When invisible (you can see its hidden now) the dequed cell is now hidden, no clue why it is happening

CollectionViewCell: 0x7f9dbb5897e0; baseClass = UICollectionViewCell; frame = (0 3.5; 209 96); clipsToBounds = YES; hidden = YES; opaque = NO; layer = <CALayer: 0x7f9dbb590220>>

indexPathsForVisibleItems is returning nil.

Answer Source

Okay, finally after digging out into this like hell, I found the problem. 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.

So my advise to all who face this problem is to check all the places from where you call reloadData for collectionview, that will lead to some clue.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download