Reputation: 314
I have an array of item IDs that backs a collection view. As the user scrolls through the collection view, each cell gets the object for that ID, then the image associated with that object. If an object happens not to have an image associated with it, I would like to delete that item ID from the array, and then update the collection view onscreen. The problem is that there are a lot of objects without images (lots of updating) and I need to update the collection view immediately (no time for animation).
Using reloadData
causes the collection view to flicker as each object is removed. Using deleteItemsAtIndexPaths
requires animations which are undesirable. Any way to remove an item from a collection view without animation that's not reloadData
?
Upvotes: 4
Views: 2651
Reputation: 3603
Here's a Swift 5 version with a slightly different way to do it:
UIView.performWithoutAnimation {
self.collectionView.performBatchUpdates({
self.collectionView.insertItems(at: indexPaths)
}, completion: nil)
}
Upvotes: 5
Reputation: 8322
you need to reload particular row with disable animation option .
[UIView setAnimationsEnabled:NO];
[collectionView performBatchUpdates:^{
[collectionView reloadItemsAtIndexPaths:indexPaths];
} completion:^(BOOL finished) {
[UIView setAnimationsEnabled:YES];
}];
Upvotes: 2