【发布时间】:2015-06-02 23:16:49
【问题描述】:
CollectionViewController.m 第 439 行 __50-[CollectionViewController photoLibraryDidChange:]_block_invoke
致命异常:NSInternalInconsistencyException 尝试删除并重新加载相同的索引路径({length = 2, path = 0 - 26007})
- (void)photoLibraryDidChange:(PHChange *)changeInstance
{
// Call might come on any background queue. Re-dispatch to the main queue to handle it.
dispatch_async(dispatch_get_main_queue(), ^{
// check if there are changes to the assets (insertions, deletions, updates)
PHFetchResultChangeDetails *collectionChanges = [changeInstance changeDetailsForFetchResult:self.assetsFetchResults];
if (collectionChanges) {
// get the new fetch result
self.assetsFetchResults = [collectionChanges fetchResultAfterChanges];
UICollectionView *collectionView = self.collectionView;
if (![collectionChanges hasIncrementalChanges] || [collectionChanges hasMoves]) {
// we need to reload all if the incremental diffs are not available
[collectionView reloadData];
} else {
// if we have incremental diffs, tell the collection view to animate insertions and deletions
[collectionView performBatchUpdates:^{
NSIndexSet *removedIndexes = [collectionChanges removedIndexes];
if ([removedIndexes count]) {
[collectionView deleteItemsAtIndexPaths:[removedIndexes aapl_indexPathsFromIndexesWithSection:0]];
}
NSIndexSet *insertedIndexes = [collectionChanges insertedIndexes];
if ([insertedIndexes count]) {
[collectionView insertItemsAtIndexPaths:[insertedIndexes aapl_indexPathsFromIndexesWithSection:0]];
}
NSIndexSet *changedIndexes = [collectionChanges changedIndexes];
if ([changedIndexes count]) {
[collectionView reloadItemsAtIndexPaths:[changedIndexes aapl_indexPathsFromIndexesWithSection:0]];
}
} completion:NULL];
}
[self resetCachedAssets];
}
});
}
我无法复制该问题。可能是什么问题呢?非常感谢!
【问题讨论】:
-
我以前见过,最近无法重现,但我现在一直看到的是断言失败 *** -[UICollectionView _endItemAnimations] 中的断言失败,/ SourceCache/UIKit/UIKit-3318.93/UICollectionView.m:3720 然后 *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“尝试从第 0 节中删除第 9 项,它在更新前仅包含 9 个项目”。这很奇怪,因为我的代码与示例中的应用程序完全相同,只是应用程序更复杂,而且它基于 Swift。 :(
-
另外,我用这种方法看到的另一个问题与最终项目数与先前计数加上总和不匹配的断言错误有关。我相信计算这些索引并将其传递给侦听器的方式可能存在问题,或者在获取结果更新后,我们可能必须对数组进行额外验证,以验证集合视图的当前状态拉。老实说,这是我目前正在开发的应用程序中最令人沮丧的部分之一。
-
有人创造了雷达吗?我会做。我测试了更新到 iOS 10 和 Swift 3 的最新代码,但它仍然经常崩溃。
-
我已经测试了类似的代码,这些代码在使用 Xcode 8 beta 2 的 iOS 10 中发生了同样的错误,并且它不再崩溃了。正如我所怀疑的,这是 UIKit 中的一个错误。
标签: ios objective-c ios8 collectionview photokit