【问题标题】:UICollectionView Assertion failure in deleteItemsAtIndexPathsdeleteItemsAtIndexPaths 中的 UICollectionView 断言失败
【发布时间】:2012-12-04 16:17:00
【问题描述】:

这是我的错误:

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

我这样称呼它:

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

为什么会这样,有什么想法吗?

【问题讨论】:

  • 你有什么解决办法吗?

标签: iphone ios xcode uicollectionview


【解决方案1】:

您是否也从模型中删除了该项目?因此,例如,如果行数、节数和它们呈现的内容取自数组字典,其键表示节,每个数组表示行,那么如果您使用 deleteItemsAtIndexPaths 删除一行,您有责任相应地更新字典。 UICollectionView 不会为你做的。

【讨论】:

  • 就我而言,不更新模型之前deleteItemAtIndexPath错误原因跨度>
  • 这对我有用。应标记为解决方案
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    当您调用 deleteItemsAtIndexPaths: 时,检查您的集合视图是否正忙于其他事情。 我在使用 insertItemsAtIndexPaths: 方法时遇到了同样的问题,结果证明这是由我的代码中的错误引起的——我在调用 [my collectionView reloadData] 后立即调用了 [myCollectionView insertItemsAtIndexPaths:] 。因此,在调用 insertItemsAtIndexPaths 的那一刻:我的集合视图正在重新加载其数据。在我修复了这个bug之后,断言失败的问题就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 2012-09-17
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多