Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete an item from a collection view without animation?

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?

like image 405
Hex Bob-omb Avatar asked Oct 20 '25 21:10

Hex Bob-omb


2 Answers

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)
}
like image 188
Skoua Avatar answered Oct 23 '25 12:10

Skoua


you need to reload particular row with disable animation option .

[UIView setAnimationsEnabled:NO];

[collectionView performBatchUpdates:^{
    [collectionView reloadItemsAtIndexPaths:indexPaths];
} completion:^(BOOL finished) {
    [UIView setAnimationsEnabled:YES];
}];
like image 35
KKRocks Avatar answered Oct 23 '25 12:10

KKRocks