iOS 10 : NSFetchedResultsController + UICollectionView, SIGABRT on performBatchUpdates

标签 ios objective-c uicollectionview nsfetchedresultscontroller sigabrt

我正在使用这个 gist用于 FRC 和 UICollectionView。这在 iOS 9 之前一直运行良好。

现在,在 iOS 10 中,有时我的应用程序会在 collectionviewperformBatchUpdates 处因 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( ma​​in 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/

相关文章:

ios - Alamofire 无法使用 cocoapods 构建

ios - 如何修复 Objective-C 中的内存泄漏?

iphone - 如何在 for 循环中使用动画设置按钮 alpha?

ios - Parse.com WhereKey :containedIn doesn`t show any results - objectId

iphone - 3G网络中NSPOSIXErrorDomain Code=12 "Cannot allocate memory"

ios - NSURLSessionDownloadTask 有时会导致零数据

ios - 通过手势交换单元格的位置

swift - 基于 UILabel 文本的 UICollectionReusableView 高度

objective-c - 制作 UIBezierPath 的独立副本?

swift - 相对于框架宽度和纵横比的动态 UICollectionViewCell 宽度