Last active
January 26, 2016 04:34
-
-
Save thornpig/8daeba3a42935718d8e7 to your computer and use it in GitHub Desktop.
Make sure reused cell presents the right picture with GCD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id imageSource = cell.imageSource; | |
dispatch_async(queue, ^{ | |
//block captures imageSource | |
UIImage *thumbNail = getImageFromSource(imageSource); | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
//block captures cell | |
//if imageSource does not match cell.imageSource, it means the cell is resued before the background thread returns the image, | |
// and the image requested for the already invisible cell may be returned after the current cell obtains its image, in which case | |
// the returned image should not be used. | |
if ([imagaeSource isEqualToArray: cell.imageSource]) | |
{ | |
cell.imageView.image = thumbNail; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment