Reputation: 28278
I have an UIImageView that tries to load an image and if it does not exist I make a call to download the image. Once the image is downloaded a NSNotification is sent and the UIImageView.image is set to the downloaded image. This is working but it takes a few seconds after the image is set for it to be shown in the UIImageView. Again the notification is sent AFTER the image is downloading so the delay is not the download of the image.
Here is the notification:
- (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 ];
}
}
All of this is used in a UIScrollView with paging enabled, how do I get these images to show up immediately after the notification.
Upvotes: 1
Views: 282
Reputation: 54603
Perhaps you're not setting it in the main thread. All UI work needs to be done there.
- (void)recieveImageDownloadUpdate:(NSNotification *)notification {
if ([[item valueForKey:@"FlipBookPhotoID"] intValue] == imgView1.tag) {
dispatch_async(dispatch_get_main_queue(), ^{
imgView1.image = [....]
});
}
}
Upvotes: 5