Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView性能更新崩溃_Ios_Objective C_Uicollectionview - Fatal编程技术网

Ios UICollectionView性能更新崩溃

Ios UICollectionView性能更新崩溃,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我正在使用UICollectionView显示画廊图像,以便自定义照片选择。无论如何,问题是,当用户单击可能位于iCloud而不在设备上的图像时,用户单击“完成” 应用程序在第行崩溃,[collectionView性能更新:出现错误: “NSInternalInconsistencyException”。我知道这个错误意味着什么,但无法设法解决它 代码: dispatch_async(dispatch_get_main_queue(), ^{ PHFetchResultChangeDe

我正在使用UICollectionView显示画廊图像,以便自定义照片选择。无论如何,问题是,当用户单击可能位于iCloud而不在设备上的图像时,用户单击“完成”

应用程序在第行崩溃,
[collectionView性能更新:
出现错误:

“NSInternalInconsistencyException”。我知道这个错误意味着什么,但无法设法解决它

代码:

dispatch_async(dispatch_get_main_queue(), ^{

    PHFetchResultChangeDetails *collectionChanges = [changeInstance changeDetailsForFetchResult:self.fetchResult];
    if (collectionChanges) {

        self.fetchResult = [collectionChanges fetchResultAfterChanges];

        UICollectionView *collectionView = self.collectionView;
        NSArray *removedPaths;
        NSArray *insertedPaths;
        NSArray *changedPaths;

        if ([collectionChanges hasIncrementalChanges]) {
            NSIndexSet *removedIndexes = [collectionChanges removedIndexes];
            removedPaths = [self indexPathsFromIndexSet:removedIndexes withSection:0];

            NSIndexSet *insertedIndexes = [collectionChanges insertedIndexes];
            insertedPaths = [self indexPathsFromIndexSet:insertedIndexes withSection:0];

            NSIndexSet *changedIndexes = [collectionChanges changedIndexes];
            changedPaths = [self indexPathsFromIndexSet:changedIndexes withSection:0];

            BOOL shouldReload = NO;

            if (changedPaths != nil && removedPaths != nil) {
                for (NSIndexPath *changedPath in changedPaths) {
                    if ([removedPaths containsObject:changedPath]) {
                        shouldReload = YES;
                        break;
                    }
                }
            }

            if (removedPaths.lastObject && ((NSIndexPath *)removedPaths.lastObject).item >= self.fetchResult.count) {
                shouldReload = YES;
            }

            if (shouldReload) {
                [collectionView reloadData];

            } else {

                [collectionView performBatchUpdates:^{
                    if (changedPaths) {
                        [collectionView reloadItemsAtIndexPaths:changedPaths];

                    }

                    if (removedPaths) {
                        [collectionView deleteItemsAtIndexPaths:removedPaths];
                    }

                    if (insertedPaths) {
                        [collectionView insertItemsAtIndexPaths:insertedPaths];
                    }

                    if ([collectionChanges hasMoves]) {
                        [collectionChanges enumerateMovesWithBlock:^(NSUInteger fromIndex, NSUInteger toIndex) {
                            NSIndexPath *fromIndexPath = [NSIndexPath indexPathForItem:fromIndex inSection:0];
                            NSIndexPath *toIndexPath = [NSIndexPath indexPathForItem:toIndex inSection:0];
                            [collectionView moveItemAtIndexPath:fromIndexPath toIndexPath:toIndexPath];
                        }];
                    }

                } completion:^(BOOL finished) {

                }];
            }

            [self resetCachedAssets];
        } else {
            [collectionView reloadData];

        }
    }
    else {

    }
});