我正在使用PSTCollectionView 类从 iPhone 相机胶卷中加载照片。我希望照片在加载时出现,而不是等到所有内容都被读取。我的代码如下所示:
-(void) loadAssetGroups {
void (^assetGroupEnumerator)
(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
NSLog(@"group....%@",[group valueForProperty:ALAssetsGroupPropertyName]);
[self loadAssetForGroup:group];
}
};
void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) {
NSLog(@"A problem occured. Error: %@", error.localizedDescription);
};
[[ImagePickerViewController defaultAssetsLibrary] enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:assetGroupEnumberatorFailure];
}
-(void) loadAssetForGroup:(ALAssetsGroup*)group {
ALAssetsFilter *filter = [ALAssetsFilter allPhotos];
[group setAssetsFilter:filter];
__block NSMutableArray *indexes = [NSMutableArray arrayWithCapacity:0];
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result == nil)
{
return;
}
if (![self.allPhotos containsObject:result]) {
[self.assets setValue:result forKey:[result valueForProperty:ALAssetPropertyURLs]];
[self.allPhotos addObject:result];
[indexes addObject:[NSIndexPath indexPathForItem:[self.allPhotos count]-1 inSection:0]];
[self.collectionView performSelectorOnMainThread:@selector(insertItemsAtIndexPaths:) withObject:[NSArray arrayWithObject:[NSIndexPath indexPathForItem:self.allPhotos.count-1 inSection:0]] waitUntilDone:NO];
}
}];
}
从控制台我看到 collectionView 正在cellForItemAtIndexPath
为前几个对象调用它的 dataSource 方法(这将在屏幕上可见),但我需要等待所有照片都被读取,直到我看到 collectionView 刷新。
有没有办法让它更“随时随地”运行?