I have a UITableView-like setup in my app. It's a scrolling view of magazine cover thumbnails, and the thumbnail images only get loaded when they are about to become visible. The scrolling was really lagging on the device, as I was loading three images from disk for every "cell." So, I'm using GCD to load an image in the background, then set it to a UIImageView in the main thread, but setting the image to the image view in the main thread still causes jerkiness when scrolling. Here's the relevant code...
Code:
NSString *magDirectoriesDirectory = [FileUtilities magDirectoriesDirectory];
NSString *magDirectory = [magDirectoriesDirectory stringByAppendingPathComponent:magTitle];
NSString *coverImagePath = [magDirectory stringByAppendingPathComponent:COVER_IMAGE_NAME];
dispatch_async(queue, ^{
UIImage *image = [UIImage imageWithContentsOfFile:coverImagePath];
dispatch_async(dispatch_get_main_queue(), ^{
magCoverImageView.image = image;
});
});
I'm know that it's setting the thumbnail to the image view that causes the problem because when I comment that line of code, it runs smoothly.
I also load a shadow image at the same time I load the thumbnail image.
Code:
UIImage *shadow = [UIImage imageNamed:@"Rack_MagShadow.png"];
shadowImageView.image = shadow;
Strangely, this causes no lag at all.
So, why is setting the thumbnail image to the image view causing a big lag, while setting the shadow image doesn't? They're the same size, by the way.