Every now and again I get this error when reloading a UICollectionview and I don't think that the error is indicative because the collectionview shouldn't be updating before this call
-(void)loadGallery:(void(^)())completion
{
[self enumerateAssetsWithCompletion:^(BOOL success, NSMutableArray *assets) {
if (success)
{
self.photos = [assets mutableCopy];
@try {
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadData];
} completion:^(BOOL finished) {
completion();
}];
}
@catch (NSException *exception) {
DLog(@"DEBUG: failure to batch update. %@", exception.description);
}
}
}];
}
- (void)enumerateAssetsWithCompletion:(void(^)(BOOL success,NSMutableArray *assets))completionBlock {
ALAssetsLibrary* al = [[self class] sharedLibrary];
__block NSMutableArray* mutableAssets = [NSMutableArray new];
[al enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup* group, BOOL* stop) {
if (group == nil) {
//self.groups = [mutableGroups copy];
if (completionBlock) {
completionBlock(YES,mutableAssets);
}
}
else {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result)
{
[mutableAssets addObject:result];
}
}];
}
} failureBlock:^(NSError* error) {
ELog(@"Failed to enumerate groups. Error: %@.", error);
if (completionBlock)
completionBlock(NO,nil);
}];
}
Error :
DEBUG: failure to batch update.
Invalid update: invalid number of items in section 0.
The number of items contained in an existing section after the update
(352) must be equal to the number of items contained in that section before the update (0),
plus or minus the number of items inserted or deleted from that section
(0 inserted, 0 deleted)
and plus or minus the number of items moved into or out of that section
(0 moved in, 0 moved out).