有一个从block中获取的值,我希望返回到下面的方法中,这个block好像是异步的,不知道怎么样实现?
-(UIImage*) imageAtIndex:(NSUInteger)index
{
UIImage *image;
[self.album enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:index] options:0 usingBlock: ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
//set image in here
}];
return image;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
-(void) imageAtIndex:(NSUInteger)index //since block is async you may not be able to return the image from this method
{
UIImage *image;
[self.album enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:index] options:0 usingBlock: ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
//set image in here
dispatch_async(dispatch_get_main_queue(), ^{ //if UI operations are done using this image, it is better to be in the main queue, or else you may not need the main queue.
[self passImage:image]; //do the rest of the things in `passImage:` method
});
}];
}这是我的实现方法,你试试吧