gpt4 book ai didi

iphone - 无法从异步 block 向主线程发送参数

转载 作者:行者123 更新时间:2023-11-28 22:42:23 25 4
gpt4 key购买 nike

我有以下方法,它在拍摄照片后从 UIImagePicker 中检索 ALAsset。然后它尝试通过主线程将此 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(), ^ block 时,result 显示为 nil。任何人都知道我在做什么做错了吗?

最佳答案

引用UIImagePickerController to use for a 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
});
// });
}

关于iphone - 无法从异步 block 向主线程发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14133770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com