开发者

loadView is faster than getting images via Assets

So, in init function I am getting images via AssetsLibrary

//initWithNibName:

photoArray = [[NSMutableArray alloc ]init];
    ALAssetsLibrary *asset = [[ALAssetsLibrary alloc] init];
    void (^enumerateGroup)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
    {
        if (result != nil) {
            [photoArray addObject:result];
            NSLog(@"%@", result);
        }

    };
    void (^enumerationBlock)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
    {
        if (group != nil) {
            [group enumerateAssetsUsingBlock:enumerateGroup];
        }
    };
    [asset enumerateGroupsWithTypes:ALAssetsGroupAll 
                         usingBlock:enumerationBlock 
                       failureBlock:^(NSError *error) {NSLog(@"Something went wrong");}];
    [asset release];

//loadView

- (void)loadView
 {
UIView *view = [[UIView alloc ] init];
NSLog(@"%d", [photoArray count]);
self.view = view;
[view release];
}

Log from console:

2011-06-24 18:55:12.255 xxx[9450:207] 0 //

2011-06-24 18:55:12.306 xxx[9450:207] ALAsset - Type:Photo, URLs:{ "public.jpeg" = "assets-library://asset/asset.JPG?id=1000000001&ext=JPG";

And I am confused. As you can see in the log, loadView executed code faster than initWithNibName. This is because getting images via AssetLibrary take some time. But I think all of this code is executing in one thread, so开发者_开发百科 loadView should wait, for initWithNibName.


The documentation for -enumerateGroupsWithTypes:... and -enumerateAssetsUsingBlock:... doesn't say that those methods execute synchronously. From what you've found, it looks like they do their enumeration on a different thread so that you don't have to wait.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜