I usually don't ask for help but this time I really need it.
I have an UICollectionViewinto an UIViewController. I have tried using default UICollectionViewFlowLayout or subclassing it trying to solve this annoying problem.
When I started to rotate the app so fast (from portrait to landscape and going back to portrait) I'm getting this errors:
*** Assertion failure in -[UICollectionViewData validateLayoutInRect:], /SourceCache/UIKit/UIKit-2935.138/UICollectionViewData.m:357
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView recieved layout attributes for a cell with an index path that does not exist: {length = 2, path = 2 - 4}'
What I have tried:
- Under
viewWillLayoutSubviewsI have tried with[self.collectionView reloadData];or[self.collectionView.collectionViewLayout invalidateLayout]; setting [UIView setAnimationEnabled: NO]; in willRotateToInterfaceOrientation setting [UIView setAnimationEnabled: YES]; in didRotateToInterfaceOrientation- Tried what I found in this link UICollectionView assertion error on stale data
Digging about similar problems I found those 3 but none of them is what I'm looking for:
- Crash when reloading collectionView frequently
- UICollectionView performBatchUpdates cause collectionview misplace while rotating the device
- UICollectionView recieved layout attributes for a cell with an index path that does not exist
All the data is downloaded before show theUICollectionView and I'm using cell created in XIB.
I guess it's about spamming invalidateLayout because the UICollectionView has not finished the last "layout process" when the app is calling invalidateLayout again... but I'm not sure.