I have a table view with an image that is being loaded lazily using grand central dispatch. I have used an async queue with two serial queues inside, the first one to download the image and the second queue to set the image to the cell. This method seems to have a laggin behavior in scrolling.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
__block UIImage *image = nil;
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:artist.imImage]]];
});
dispatch_sync(dispatch_get_main_queue(), ^{
cell.artistImage.image = image;
});
});
And then I tried with a single asynchronous queue to download image and then get the main queue inside and set image. Even I dont feel this method being much suitable. I think I am missing something here.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:artist.imImage]]];
dispatch_async(dispatch_get_main_queue(), ^{
cell.artistImage.image = image;
});
});
Is it like I am missing something here or is it some other problem ?