GCD线程通信11

在storyborad中拖拽UIImageView

//关联属性

@property (weak,nonatomic) IBOutlet UIImageView *imageView;

- (void)touchesBegan:(NSSet *)touches withEvent :(UIEvent *)event{

//图片的网络途径

NSURL *url = [NSURL URLWithString:@"http://img.pconline.com.cn/images/photoblog/9/9/8/1/9981681/200910/11/1255259355826.jpg"]

//加载图片

NSData *data = [NSData dataWithContentsOfURL:url];

//生成图片

UIImage *image = [UIImage imageWithData:data];

//回到主线程

dispatch_async(dispatch_get_main_queue(),^{

self.imageView.image = image;

});

}

你可能感兴趣的:(GCD线程通信11)