如何异步设置图像到许多UIImageView?

时间:2013-07-28 13:05:31

标签: ios cocoa-touch asynchronous uiimageview

我们尝试将相册中的图像异步加载到不同的UIImageView。但现在,在大延迟之后,所有图像都会加载在一起。

- (void)loadAllAssetWithHandler:(void (^)(ALAsset *))hanlderAssetDidLoad
{
    ALAssetsLibraryAccessFailureBlock blockFailure =  ^(NSError *error){
        NSLog(@"ERROR = %@", error.description);
    };

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
    {
        if (group == nil) {
            return;
        }
        if([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString: @"album"])
        {
            [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
             {
                 if(asset == nil) {
                     return;
                 }
                 hanlderAssetLoad(asset);
             }];
            return;
        }
    };

    // Enumerate Albums
    [library enumerateGroupsWithTypes: ALAssetsGroupAll
                           usingBlock: assetGroupEnumerator
                         failureBlock: blockFailure];
    [library release];    
}

    [self loadAllAssetsWithHandlert:^(ALAsset *asset) {

            UIImageView *imageView = [self nextImageVIew];
            imageView.image = [UIImage imageWithCGImage: asset.defaultRepresentation.fullResolutionImage];  //or thumbnail
        }];

那么,我们如何将图片轮流上传到UIImageView(每次上传后立即)?

0 个答案:

没有答案