iOS UIImage 通过旧图像

iOS UIImage Passes Old Image

在我的应用程序中,我使用 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;   
}
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];