deleteItemsAtIndexPaths中的UICollectionView断言失败

Dev*_*fly 6 iphone xcode ios uicollectionview

这是我的错误:

*** Assertion failure in -[PSUICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-2372/UICollectionView.m:2801
Run Code Online (Sandbox Code Playgroud)

我这样称呼它:

[self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:1 inSection:1]]];
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况,有什么想法吗?

Val*_*adu 7

你也从你的模型中删除了该项目吗?因此,例如,如果它们所呈现的行数,行数和内容是从数组字典中获取,其中键表示各部分,每个数组表示行,那么如果删除一行,则deleteItemsAtIndexPaths负责更新字典因此.UICollectionView不会为你做的.


Pet*_*oné 5

请注意,您尝试从第1节删除索引1.索引和部分都从0开始.

我是这样做的:

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];
Run Code Online (Sandbox Code Playgroud)