Trying to add a a Supplementary view into my UICollectionView
as a header. I\'m having issues getting it to work.
I use a custom UICollectionViewFlowL
The answers in this topic are quite old, and do not work in iOS8 and iOS9. If you are still having the described issue, check out the following topic: UICollectionView and Supplementary View crash
EDIT:
Here is the answer, in case the link becomes invalid:
If you are using custom layout in your collection view, check if its datasource is nil in:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
The result should look something like this:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
if (self.collectionView.dataSource != nil) {
// Your layout code
return array;
}
return nil;
}
This change resolves the following issue:
- Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:]
You can also check the following topic, however it didn't resolve anything in my case:
Removing empty space, if the section header is hidden in the UICollectionView
Hope it will help you, and you won't waste as much time as I did.