0

我有以下方法,它在拍摄照片后ALAsset从中检索。UIImagePicker然后它尝试ALAsset通过主线程将其发送到我的另一个方法:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSURL *imageURL = [[info valueForKey:UIImagePickerControllerReferenceURL] retain];
    __block ALAsset *result;

    [self.assetsLibrary assetForURL:imageURL resultBlock:^(ALAsset *asset)
    {
        result = [asset retain];

        dispatch_async(dispatch_get_main_queue(), ^
        {
            [self loadPhotoImageViewWithAsset:result];
            [self dismissModalViewControllerAnimated:YES];
            [imageURL release];
            [result release];
        });
    }
    failureBlock:^(NSError *error)
    {

    }];
}

当我进入 时dispatch_async(dispatch_get_main_queue(), ^ blockresult显示为nil。有人知道我在这里做错了什么吗?

4

1 回答 1

2

参考UIImagePickerController 用于 UIImageView结果显示为零。

像这样使用:

 [self.assetsLibrary assetForURL:imageURL resultBlock:^(ALAsset *asset)
{
    result = [asset retain];
    [self loadPhotoImageViewWithAsset:result];
    [self dismissModalViewControllerAnimated:YES];
    [imageURL release];
    [result release];   
}
failureBlock:^(NSError *error)
{

}];

改变你的loadPhotoImageViewWithAsset方法

-(void)loadPhotoImageViewWithAsset:(ALAsset *)asset
{
  //dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
   //dispatch_async(queue, ^{
    dispatch_async(dispatch_get_main_queue(), ^
    {
     //here code for loading image
    });
  // });
}
于 2013-01-03T06:06:25.307 回答