UICollectionView 在 insertSections 上崩溃,endItemAnimationsWithInvalidationContext:tentativelyForReordering:

UICollectionView crashing on insertSections, with endItemAnimationsWithInvalidationContext:tentativelyForReordering:

我正在尝试向我的集合视图添加一个新部分,因为新部分的数据价值已添加到数据源中。我是这样做的:

self.conversationCollectionView.performBatchUpdates({
    self.conversationCollectionView.insertSections(NSIndexSet(index: 0))
}, completion: {
(finished: Bool) -> Void in
})

我也是从不使用 performBatchUpdates 开始的。无论哪种方式,我每次都会遇到此崩溃:

Assertion failure in -[MyApp _endItemAnimationsWithInvalidationContext:tentativelyForReordering:]

这是在 运行 行 insertSections.

之后

我有 0 个以上的索引。我试过将该索引号更改为其他值,包括正确的值。我每次都会遇到同样的崩溃。这似乎不是 'out of bounds' 类错误。我不确定它是什么。

你有没有更新你的

UICollectionViewDataSource

函数

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

根据您的新版块计数?

当集合视图不是最顶层视图时,我 运行 遇到了同样的问题。