繁体   English   中英

deleteItemsAtIndexPaths中的UICollectionView断言失败

[英]UICollectionView Assertion failure in deleteItemsAtIndexPaths

这是我的错误:

*** Assertion failure in -[PSUICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-2372/UICollectionView.m:2801

我这样称呼它:

[self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:1 inSection:1]]];

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

你也从你的模型中删除了该项目吗? 因此,例如,如果它们所呈现的行数,行数和内容是从数组字典中获取,其中键表示节,每个数组表示行,那么如果使用deleteItemsAtIndexPaths删除一行, deleteItemsAtIndexPaths需要更新字典相应。 UICollectionView不会为你做这件事。

请注意,您尝试从第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];

当你调用deleteItemsAtIndexPaths时,检查你的集合视图是不是忙于其他东西。 我遇到了与insertItemsAtIndexPaths:方法相同的问题,结果发现它是由我的代码中的错误引起的 - 我在调用[my collectionView reloadData]后立即调用[myCollectionView insertItemsAtIndexPaths:]。 因此,在调用insertItemsAtIndexPaths时:我的集合视图正在重新加载其数据。 修复此错误后,断言失败的问题已经消失。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM