I m getting this error on performing insertItemsAtIndexPaths in UICollectionView
Assertion failure in:
-[UICollectionViewD
Here is a non-hack, docs-based answer to the problem. In my case, there was a condition according to which I would return a valid or a nil supplementary view from collectionView:viewForSupplementaryElementOfKind:atIndexPath:. After encountering the crash, I checked the docs and here is what they say:
This method must always return a valid view object. If you do not want a supplementary view in a particular case, your layout object should not create the attributes for that view. Alternatively, you can hide views by setting the hidden property of the corresponding attributes to YES or set the alpha property of the attributes to 0. To hide header and footer views in a flow layout, you can also set the width and height of those views to 0.
There are other ways to do this, but the quickest seems to be:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewFlowLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
return ? collectionViewLayout.headerReferenceSize : CGSizeZero;
}