UICollectionView Assertion failure

前端 未结 14 2201
别那么骄傲
别那么骄傲 2020-11-29 17:27

I m getting this error on performing insertItemsAtIndexPaths in UICollectionView

Assertion failure in:

-[UICollectionViewD         


        
14条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 18:21

    In my case, the problem was the way I was creating my NSIndexPath. For example, to delete the 3rd cell, instead of doing :

    NSIndexPath* indexPath = [NSIndexPath indexPathWithIndex:2];
    [_collectionView deleteItemsAtIndexPaths:@[indexPath]];
    

    I needed to do :

    NSIndexPath* indexPath = [NSIndexPath indexPathForItem:2 inSection:0];
    [_collectionView deleteItemsAtIndexPaths:@[indexPath]];
    

提交回复
热议问题