标签:
1 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 2 { 3 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 4 dispatch_async(queue, ^{ 5 NSLog(@"--download--%@", [NSThread currentThread]); 6 // 下载图片 7 NSURL *url = [NSURL URLWithString:@"http://news.baidu.com/z/resource/r/image/2014-06-22/2a1009253cf9fc7c97893a4f0fe3a7b1.jpg"]; 8 NSData *data = [NSData dataWithContentsOfURL:url]; // 这行会比较耗时 9 UIImage *image = [UIImage imageWithData:data]; 10 11 // 回到主线程显示图片 12 dispatch_async(dispatch_get_main_queue(), ^{ 13 NSLog(@"--imageView--%@", [NSThread currentThread]); 14 self.imageView.image = image; 15 }); 16 }); 17 }
标签:
原文地址:http://www.cnblogs.com/PJHome/p/5157630.html