The problem in your earlier code was that you were creating the UIImage
from the GIF data on the main queue. Since decoding a GIF (especially one with many frames) can take some time, you were blocking the main thread, which is why the table view stopped scrolling momentarily each time it needed to display another image.
The problem in your later code is that you are modifying the image
property of a UIImageView
on a background queue. You must only modify user interface objects on the main queue.
What you need to do is create the UIImage
on a background queue, then dispatch back to the main queue to update the UIImageView
's image
property. Thus:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
NSData *data = [[ImageCache sharedImageCache] GetImage:post[@"gif"]];
UIImage *image = [UIImage animatedImageWithAnimatedGIFData:data];
dispatch_async(dispatch_get_main_queue(), ^{
postGif.image = image;
}
});