Skip to content

Instantly share code, notes, and snippets.

@0oneo
Last active December 23, 2015 03:19
Show Gist options
  • Select an option

  • Save 0oneo/6572272 to your computer and use it in GitHub Desktop.

Select an option

Save 0oneo/6572272 to your computer and use it in GitHub Desktop.
NSArray *images = @[@"http://example.com/image1.png",
@"http://example.com/image2.png",
@"http://example.com/image3.png",
@"http://example.com/image4.png"];
dispatch_queue_t imageQueue = dispatch_queue_create("Image Queue",NULL);
for (NSString *urlString in images) {
dispatch_async(imageQueue, ^{
NSURL *url = [NSURL URLWithString:urlString];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
NSUInteger imageIndex = [images indexOfObject:urlString];
UIImageView *imageVIew = (UIImageView *)[self.view viewWithTag:imageIndex];
if (!imageView) return;
dispatch_async(dispatch_get_main_queue(), ^{
// Update the UI
[imageVIew setImage:image];
});
});
}
// Continue doing other stuff while images load
@0oneo
Copy link
Copy Markdown
Author

0oneo commented Sep 15, 2013

blog url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment