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
I also got this annoying error:
*** Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /SourceCache/UIKit/UIKit-3347.44/UICollectionView.m:1400
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView dataSource is not set'
and I found some people solving this error by doing
- (void)dealloc {
self.collectionView = nil;
}
or in swift:
deinit {
collectionView = nil
}
however neither of these solved my crash. I tried a few things out and the following "hack" solved this annoying bug:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
if collectionView.dataSource != nil {
return someHeaderSize
} else {
return CGSizeZero
}
}