2015-04-01 45 views
-1

在我的应用程序中,我使用API​​从服务器获取图像。使用下面的代码,它可以按照大小顺序获取图像,以更好的质量取代自己。iOS UIImage传递旧图像

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    NSURL *imageURL = [NSURL URLWithString: [NSString stringWithFormat:@"%@", [[[self.information objectForKey:@"images"]objectForKey:@"normal"] description]]]; 
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; 
    self.shotImage = [UIImage imageWithData:imageData]; 
    self.image.image = self.shotImage; 
}); 

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    NSURL *imageURL = [NSURL URLWithString: [NSString stringWithFormat:@"%@", [[[self.information objectForKey:@"images"]objectForKey:@"hidpi"] description]]]; 
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; 
    UIImage *image = [UIImage imageWithData:imageData]; 
    self.image.image = self.shotImage; 
}); 

此外,如果你按图片,它会带你另一个ViewController,其中图像是全屏。

然而,即使我在点击它之前等待高质量的加载,在PrepareForSegue方法中,它仍然只能通过原始的低质量版本。

看到PrepareForSegue

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    FullSizeImageViewController *vc = [segue destinationViewController]; 
    UIImage *img = [[UIImage alloc] init]; 
    img = self.shotImage; 
    vc.shotImage = img; 
} 

回答

0
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    NSURL *imageURL = [NSURL URLWithString: [NSString stringWithFormat:@"%@", [[[self.information objectForKey:@"images"]objectForKey:@"hidpi"] description]]]; 
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; 
    UIImage *image = [UIImage imageWithData:imageData]; 
    self.image.image = self.shotImage; 
}); 

下面的代码在这段代码看起来像你错过了这行:

self.shotImage = [UIImage imageWithData:imageData]; 
+0

不,图像的更新工作正常,它只是传递图像 – 2015-04-01 15:13:48

+0

是的。但你传递self.shotImage是继续,但没有更新它,当得到新的形象 – 2015-04-01 16:07:41

+0

而你可以看到,你更新它时,得到低tes值 – 2015-04-01 16:11:39