The title is the error I\'m getting and I have no idea why, but here is some information so hopefully someone on here can elucidate me.
I have subclassed UICol
I scoured the forums looking for an answer and came across a few suggestions. None of them gave me the succour I needed, and eventually in the interest of meeting deadlines, I dropped the use of supplementary views altogether.
A few weeks later out of curiosity I looked around again and eventually came across the following post and now I'm back to using supplementary views again.
So, don't forget to return your:
- (NSArray<NSIndexPath *> *)indexPathsToDeleteForSupplementaryViewOfKind:(NSString *)elementKind
{
return self.removedIndexPaths;
}
to your collection view layout.
To prevent a crash you could return dummy attributes for all those indexPaths that are not valid any more. Something like this could help to prevent your crash:
UICollectionViewLayoutAttributes *layoutAttributes = self.layoutInfo[elementKind][indexPath]; // add some safety checks if this access creates an out of bounds issue
// create dummy layoutAttributes
// the workaround
if (layoutAttributes == nil) {
UICollectionViewLayoutAttributes *dummyLayoutAttributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:elementKind withIndexPath:indexPath];
dummyLayoutAttributes.frame = CGRectZero;
dummyLayoutAttributes.hidden = YES;
layoutAttributes = dummyLayoutAttributes;
}
return layoutAttributes;
This still leads to objects in your view stack that should not be there, but they are hidden and don't create a crash. The next time the UICollectionView
updates it's layout it should clean out the old hidden views.