UICollectionView Performing Updates using performBatchUpdates

前端 未结 3 1059
执笔经年
执笔经年 2020-12-07 17:41

I have a UICollectionView which I am trying to insert items into it dynamically/with animation. So I have some function that downloads images asynchronously and

3条回答
  •  旧时难觅i
    2020-12-07 18:37

    I was facing the similar issue while deleting the item from index and this is what i think we need to do while using performBatchUpdates: method.

    1# first call deleteItemAtIndexPath to delete the item from collection view.

    2# Delete the element from array.

    3# Update collection view by reloading data.

    [self.collectionView performBatchUpdates:^{
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
                [self.collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
                [self.addNewDocumentArray removeObjectAtIndex:sender.tag];
            } completion:^(BOOL finished) {
                [self.collectionView reloadData];
            }];
    

    This help me to remove all the crash and assertion failures.

提交回复
热议问题