#ios #objective-c #uicollectionview
#iOS #objective-c #uicollectionview
Вопрос:
Я использую UICollectionView для отображения изображений галереи, чтобы настроить выбор фотографий. В любом случае, проблема заключается в том, что когда пользователь нажимает на изображение, которое, возможно, находится в iCloud, а не на устройстве, пользователь нажимает Готово.
Приложение вылетает в строке [collectionView performBatchUpdates:]
с ошибкой:
«Исключение 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 amp;amp; removedPaths != nil) {
for (NSIndexPath *changedPath in changedPaths) {
if ([removedPaths containsObject:changedPath]) {
shouldReload = YES;
break;
}
}
}
if (removedPaths.lastObject amp;amp; ((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 {
}
});