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 UICollectionViewFlowLayout
as this saves me calculating the frames for the cell's myself (perhaps this is an issue?) in prepareLayout
. I then use the UICollectionViewLayoutAttributes
information to calculate a supplementary view that over lays it, I get the layout I desire.
I use performBatchUpdates:completion:
to add,remove and update the view. Insertion works fine, however deleting items is when the error shown in the title appears.
So I know why the error is happening but i don't know why it should even be happening. To clarify with an example going through a scenario that causes the issue
- Start with 1 item with 1 supplementary view 1 section
- Add two more items (
prepareLayout
sees 3 items with 3 supplementary views) - Delete item (
prepareLayout
sees 2 views with 2 supplementary views) layoutAttributesForSupplementaryViewOfKind:atIndexPath:
is called asking for attributes for index path with section:0 and item:2- Crash because it asked for attributes for a third supplementary view even though earlier it called prepare layout setting up 2 items and 2 supplementary views
- Throw hands up in resignation and despair
so the offending function as far as i can tell is:
- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath
{
return self.layoutInfo[elementKind][indexPath];
}
which of course is called automagically by the internal networking of UICollectionView
so I have no clue as to why it's asking for that supplementary view at that index path.
Anyone got any ideas? Perhaps it's how i use performBatchUpdates:completion:
but deletion worked fine until adding supplementary views. I can provide more code/explanation as necessary.