2011-12-27 54 views
1

我有一个UIImageView试图加载图像,如果它不存在,我打电话下载图像。一旦图像被下载,NSNotification被发送并且UIImageView.image被设置为下载的图像。这是行得通的,但在图像设置为在UIImageView中显示后需要几秒钟。在图像下载完成后,再次发送通知,因此延迟不是图像的下载。UIImageView.image需要几秒钟时间通过NSNotification设置时显示

以下是通知:

- (void)recieveImageDownloadUpdate:(NSNotification *)notification { 

if ([[item valueForKey:@"FlipBookPhotoID"] intValue] == imgView1.tag) { 
     // this loads the image if the tag on the UIImageView matches the notification update 
     imgView1.image = [Helpers getImageDownloadIfMissing:[[item valueForKey:@"PhotoName"] stringByReplacingOccurrencesOfString:@"_lg" withString:@""] withManufacturer:[item valueForKey:@"ManufacturerID"] withFlipBookID:[item valueForKey:@"FlipBookID"] withFlipBookPhotoID:[item valueForKey:@"FlipBookPhotoID"] shouldDownload:NO ]; 

    } 
} 

所有这一切都与寻呼一个UIScrollView用于启用,如何获取这些图像的通知后,立即显示。

+0

可以提供更多的细节... – Ali3n

+0

有一吨的代码,只是想知道如果我需要调用强制屏幕更新 – Slee

回答

5

也许你没有在主线程中设置它。所有UI工作都需要在那里完成。

- (void)recieveImageDownloadUpdate:(NSNotification *)notification { 
    if ([[item valueForKey:@"FlipBookPhotoID"] intValue] == imgView1.tag) { 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      imgView1.image = [....] 
     }); 
} 

}

+0

这是它的方法,应该抓住了这一点。我的更新通知来自dispatch_async(dispatch_get_global_queue(0,0),^ {});这使我纠正了。谢谢! – Slee

相关问题