iOS UIImage传递旧图像

时间:2015-04-01 15:06:01

标签: ios uiimageview segue

在我的应用中,我使用API​​从服务器获取图像。使用下面的代码,它按大小顺序获取图像,以更好的质量替换自己。

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;   
}

1 个答案:

答案 0 :(得分: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];
相关问题