Para esto usamos la API GCD (Grand Central Dispatch).
Este es un ejemplo de como hacerlo:
Este es el método sin crear una queue
-(void) viewWillAppear:(BOOL)animated
{
NSData *imageData = [NSData dataWithContentsOfURL:networkURL];
UIImage *image = [UIImage imageWithData:imageData];
self.imageView.image = image;
self.imageView.frame = CGRectMake(0, 0, image.size.width, image.size.heigh);
self.scrollView.contentSize = image.size;
}
Este es el método con la queue
-(void) viewWillAppear:(BOOL)animated
{
// Creo la queue
dispatch_queue_t downloadQueue = dispatch_queue_create("image downloader", NULL);
dispatch_async(downloadQueue, ^{
NSData *imageData = [NSData dataWithContentsOfURL:networkURL];
//Llamadas al UIKit en el queue principal
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *image = [UIImage imageWithData:imageData];
self.imageView.image = image;
self.imageView.frame = CGRectMake(0, 0, image.size.width, image.size.heigh);
self.scrollView.contentSize = image.size;
});
});
// Cuando no existan más bloques release
dispatch_release(downloadQueue);
}