在重新加载 UICollectionview 时,我时不时会收到此错误,我认为该错误不是指示性的,因为在此调用之前 collectionview 不应该更新
-(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);
}];
}
错误 :
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).