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.
I've posted a work around for this issue here: https://gist.github.com/iwasrobbed/5528897
In the private category at the top of your
.m
file:Then your delegate callbacks would be:
Credit for this approach goes to Blake Watters.
In my case, the problem was the way I was creating my
NSIndexPath
. For example, to delete the 3rd cell, instead of doing :I needed to do :
I ran into this very same problem when inserting the first cell into a collection view. I fixed the problem by changing my code so that I call the UICollectionView
method when inserting the first cell, but
when inserting all other cells.
Interestingly, I also had a problem with
when deleting the last cell. I did the same thing as before: just call
reloadData
when deleting the last cell.Here's a solution for this bug I've been using in my projects I thought I'd post here in case any found it valuable.
The workaround that actually works is to return a height of 0 if the cell at your supplementary view's index path is not there (initial load, you've deleted the row, etc). See my answer here:
https://stackoverflow.com/a/18411860/917104
I ran into this problem as well. Here's what happened to me:
initWithCollectionViewLayout:
, was initializing myNSFetchedResultsController
.NSManagedObjects
, add them to myNSManagedObjectContext
, which has the main thread'sNSManagedObjectContext
as aparentContext
.NSFetchedResultsController
pick up the changes and queue them up.- (void)controllerDidChangeContent:
, I would process the changes and apply them to myUICollectionView
.Intermittently, I would get the error the OP is getting and couldn't figure out why.
To fix this issue, I moved the
NSFetchedResultsController
initialization andperformFetch
to my- viewDidLoad
method and this problem is now gone. No need to call[collectionView reloadData]
or anything and all the animations are working properly.Hope this helps!