UICollectionView Assertion error in deleteItemsAtIndexPaths file

Here is my mistake:

*** Assertion failure in -[PSUICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-2372/UICollectionView.m:2801 

I call it this way:

 [self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:1 inSection:1]]]; 

Why is this happening, any ideas?

+6
source share
3 answers

Are you also removing an item from your model? So, for example, if the number of lines, sections, and content that they represent is taken from a dictionary of arrays whose keys represent sections and each array of strings, then if you delete one row with deleteItemsAtIndexPaths , you are responsible for deleteItemsAtIndexPaths dictionary accordingly. UICollectionView will not do this for you.

+7
source

Note that you are trying to remove index 1 from section 1. Both indexes and sections start 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]; 
+5
source

Make sure your collection view is not busy with anything else when you call deleteItemsAtIndexPaths :. I had the same problem with the insertItemsAtIndexPaths method: and it turned out that it was caused by an error in my code - I called [myCollectionView insertItemsAtIndexPaths:] immediately after calling [my collectionView reloadData]. So, at the time of the call to insertItemsAtIndexPaths: my view of the collection overloaded my data. After fixing this error, the problem with the approval error disappeared.

+1
source

All Articles