我有一個名爲「ComLog」的「UIImage」返回類型方法。我想從這個方法返回一個圖像。在「ComLog」方法中,我使用GCD從數組中獲取圖像值。我使用下面的代碼,「NSLog(@」qqqqqqqqqqq%@「,exiIco)」打印'image'的值,但NSLog(@「qqqqqqqqqqqq%@」,exiIco);「不要 這裏是細節:如何從GCD返回UIImage類型
-(UIImage*) ComLog
{
ExibitorInfo *currentExibitor100 = [[ExibitorInfo alloc] init];
currentExibitor100 = [self.exibitorsArray objectAtIndex:0];
imageQueueCompanyLogo = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(imageQueueCompanyLogo,^
{
UIImage *imageCompanyLogo = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:[currentExibitor100 companyLogoURL]]]];
dispatch_async(dispatch_get_main_queue(),^
{
self.exibitorIcoImageView.image = imageCompanyLogo;
exiIco = imageCompanyLogo;
NSLog(@"qqqqqqqqqqq %@", exiIco);
});
});
return exiIco;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *a = [self ComLog];
NSLog(@"It should be a image %@", a);
}
這裏所有屬性全局聲明(在「Myclass.h」文件)。我在目的C.新,如果你知道答案,請給予答覆。 在此先感謝。
你的方法返回之前。看看[這個關於GCD的問題](http://stackoverflow.com/q/18178278/1489997),也許它有幫助。 – Sebastian
我不認爲這個問題會有幫助,該方法將在隊列完成之前返回,添加'__block'不會改變它。當隊列完成時,您需要使用回調/塊來將圖像類型返回給調用方法。這裏有一些信息可以幫助你,http://cocoasamurai.blogspot.com/2011/02/practical-design-patterns-with-blocks.html – sbarow
好吧,我會看看這些話題。順便感謝評論。 :) – Tulon