Reputation: 2495
Here is my error:
*** Assertion failure in -[PSUICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-2372/UICollectionView.m:2801
I'm calling it like this:
[self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:1 inSection:1]]];
Why is this happening, any ideas?
Upvotes: 6
Views: 7933
Reputation: 1028
Check that your collection view is not busy with something else when you call deleteItemsAtIndexPaths: . I experienced the same problem with insertItemsAtIndexPaths: method, and it turned out that it was caused by a bug in my code - I called [myCollectionView insertItemsAtIndexPaths:] immediately after calling [my collectionView reloadData] . So, at the moment of calling insertItemsAtIndexPaths: my collection view was reloading its data. After I fixed this bug, the problem with assertion failure has gone.
Upvotes: 1
Reputation: 131
Note that you are trying to delete index 1 from section 1. Both index and section starts at 0.
i did it like this:
NSMutableArray *forms; // datasource item data for all the cells
int indexToDelete; // Set to the index you want to delete
...
[self.collectionView performBatchUpdates:^(void){
[forms removeObjectAtIndex:indexToDelete]; // First delete the item from you model
[self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexToDelete inSection:0]]];
} completion:nil];
Upvotes: 5
Reputation: 9231
Do you remove the item from your model as well? So, for example, if the number of rows, sections and the content they present is taken from a dictionary of arrays whose keys represent the sections and each array the rows, then if you delete one row with deleteItemsAtIndexPaths
you're responsible to update the dictionary accordingly. UICollectionView
will not do it for you.
Upvotes: 7