まず、Paul Hegarty のチュートリアル(レクチャー 9、10、および主に 11 (マルチスレッド)) をお勧めします。
ここでいくつかのサンプル コードが役に立ちます。
dispatch_queue_t imageFetchQ = dispatch_queue_create("image fetcher", NULL);
dispatch_async(imageFetchQ, ^{
NSData *imageData = [[NSData alloc] initWithContentsOfURL:self.imageURL]; // could take a while
// UIImage is one of the few UIKit objects which is thread-safe, so we can do this here
UIImage *image = [[UIImage alloc] initWithData:imageData];
// check to make sure we are even still interested in this image (might have touched away)
if (self.imageURL == imageURL) {
// dispatch back to main queue to do UIKit work
dispatch_async(dispatch_get_main_queue(), ^{
if (image) {
self.scrollView.zoomScale = 1.0;
self.scrollView.contentSize = image.size;
self.imageView.image = image;
self.imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
}
});
}
});