2015-04-01 73 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