In my app there was a UICollectionView using flowLayout and it was working beautifully in iOS 6 but fails horribly in iOS 7. As soon as I segue to the view containing my UICollectionView here's what happens:
*** Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /SourceCache/UIKit/UIKit-2903.2/UICollectionView.m:1401
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath
(UICollectionElementKindSectionHeader,<NSIndexPath: 0x145f3f50> {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil'
(<UICollectionReusableView: 0x145f9400; frame = (0 0; 320 20); layer = <CALayer: 0x145f90c0>>)
When I updated to iOS 7 I ran into this. The problem ended up being that you shouldn't be so explicit with your dataSource. If you have the following, remove it:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
return nil;
}
It will crash if you return nil
in this function:
- (UICollectionReusableView*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
Basically, the only reason you would have to return nil
is if the "kind" NSString
is not a type you expect. In that case, just delete that object in the interface builder. I had this same crash because my collection view had a footer in the interface builder but I was not calling the registerNib
code (as bneely described above) to set up a footer. I'd get to the viewForSupplementaryElementOfKind
and return nil because it was a kind I was not expecting.(which is guaranteed to cause the crash).
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