【发布时间】:2014-05-29 17:00:43
【问题描述】:
我有以下几点:
__block ALAssetsGroup* album = nil;
ALAssetsLibrary* library = [ALAssetsLibrary new];
[library enumerateGroupsWithTypes: ALAssetsGroupAlbum
usingBlock:
^ (ALAssetsGroup *group, BOOL *stop) {
if (group) {
NSString* title =
[group valueForProperty: ALAssetsGroupPropertyName];
if ([title isEqualToString: @"Test1"]) {
album = group;
*stop = YES;
NSLog(@"sd%@", album.description);
}
} else { // afterwards
self.images = [self showFirstPhotoOfGroup:album]; // (oreilly, programming ios 7, ch.17)
NSLog(@"A:%d",[_images count]); // return photo count
if (!album) {
NSLog(@"%@", @"failed to find album");
return;
}
}
}
];
NSLog(@"B:%d",[_images count]);
NSLog A:正确显示相册中的项目数为2。
NSLog B:显示为0,其实是在block之前处理的!
我理解它为什么这样做 - 但这是 Apple 提供的示例。请你告诉我如何让 _images 在块之外保持它的价值。这个块看起来有一个完全不同的范围。
多年来,我一直在尝试将专辑加载到数组中 - 但这个块示例在块之外没有保留它的值!
【问题讨论】:
标签: ios iphone objective-c icarousel