I m getting this error on performing insertItemsAtIndexPaths
in UICollectionView
Assertion failure in:
-[UICollectionViewData indexPathForItemAtGlobalIndex:],
/SourceCache/UIKit/UIKit-2372/UICollectionViewData.m:442
2012-09-26 18:12:34.432
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'request for index path for global index 805306367
when there are only 1 items in the collection view'
I have checked and my datasource contains only one element. Any insights on why this could happen? If more information is needed I can definitely provide that.
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:There are other ways to do this, but the quickest seems to be:
Just for the record, I ran into the same problem and for me the solution was to remove the header (disable them in the .xib) and as them were not needed anymore removed this method. After that everything seems fine.
My collection view was getting items from two data sources and updating them caused this issue. My workaround was to queue the data update and collection view reload together:
Check that you're returning the correct value in
numberOfSectionsInCollectionView:
The value I was using to calculate sections was nil, thus
0
sections. This caused the exception.Inserting section#0 just before inserting cells seems make UICollectionView happy.
I hit this problem myself. All the answers here seemed to present problems, except for Alex L's. Referring the update seemed to be tha answer. Here is my final solution: