GCD线程通信11

2016-06-02  本文已影响12人  Sunney

在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;

});

}

上一篇下一篇

猜你喜欢

热点阅读