我正在使用这个 gist用于 FRC 和 UICollectionView
。这在 iOS 9 之前一直运行良好。
现在,在 iOS 10 中,有时我的应用程序会在 collectionview
的 performBatchUpdates
处因 SIGABRT 信号崩溃而崩溃。即使 CollectionView
从崩溃中逃脱,它也会进入 1 或 2 个单元格的昏迷状态。
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
// Checks if we should reload the collection view to fix a bug @ http://openradar.appspot.com/12954582
if (self.shouldReloadCollectionView) {
[self.collectionView reloadData];
} else {
[self.collectionView performBatchUpdates:^{ // CRASH : Thread 1: signal SIGABRT
[self.blockOperation start];
} completion:nil];
}
}
发生这种情况是因为 UICollectionView
的新升级功能吗?解决方法是什么?
最佳答案
在做了一些研究之后,找到了解决这个问题的方法。我的应用从网络服务器获取数据并使用主线程插入数据。
我假设此信号是由于某种无效数据操作而发出的。正如我所怀疑的那样,controllerDidChangeContent
( main thread ) 线程一开始保存数据,委托(delegate)就会被调用。 [self.managedObjectContext 保存:&savingError];
这种早期调用导致 performBatchUpdates
在保存过程中沉迷于数据操作,从而导致崩溃。
将 controllerDidChangeContent
代码放入 dispatch_async
修复了 CollectionView
的崩溃和昏迷状态。我希望这对某人有所帮助。
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
dispatch_async(dispatch_get_main_queue(), ^{
// Checks if we should reload the collection view to fix a bug @ http://openradar.appspot.com/12954582
if (self.shouldReloadCollectionView) {
[self.collectionView reloadData];
} else {
[self.collectionView performBatchUpdates:^{ // No crash :)
[self.blockOperation start];
} completion:nil];
}
});
}
关于iOS 10 : NSFetchedResultsController + UICollectionView, SIGABRT on performBatchUpdates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39703820/