I'm using custom UICollectionView
on my app. However, I have a problem that make my app crash. The log for the crash:
Note: This bug doesn't occur on iOS 8
2015-05-29 11:49:26.316 app9to5[1834:607] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView recieved layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0x7fca0e00> {length = 2, path
= 0 - 14}'
> First throw call stack: (
CoreFoundation 0x039b61e4 __exceptionPreprocess + 180
libobjc.A.dylib 0x036808e5 objc_exception_throw + 44
CoreFoundation 0x039b6048 +[NSException raise:format:arguments:] + 136
Foundation 0x016954de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
UIKit 0x02be0866 __45-[UICollectionViewData validateLayoutInRect:]_block_invoke + 1793
UIKit 0x02bdfaed -[UICollectionViewData validateLayoutInRect:] + 1376
UIKit 0x02ba5603 -[UICollectionView layoutSubviews] + 173
UIKit 0x025c8964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
libobjc.A.dylib
Please help me to resolve. Thank you so much!
You should try this:
In -(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
you put this:
for(NSInteger i=0 ; i < self.collectionView.numberOfSections; i++) {
for (NSInteger j=0 ; j < [self.collectionView numberOfItemsInSection:i]; j++) {
NSIndexPath* indexPath = [NSIndexPath indexPathForItem:j inSection:i];
[attributes addObject:[self layoutAttributesForItemAtIndexPath:indexPath]];
}
}
Hope this could help.
Try invalidating the layout before you call reloadData on collection View.
[self.collectionView.collectionViewLayout invalidateLayout];
[self.collectionView reloadData];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With