使用GCD下载图片(二)

- (IBAction)downLoadImage:(id)sender {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        NSString* url=@"http://pic2.nipic.com/20090413/60867_143033029_2.jpg";
        NSData* data=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:url]];
        UIImage* image=[[UIImage alloc]initWithData:data];
        if (image!=nil) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.iv.image=image;
            });
        }
        else
        {
            NSLog(@"下载出错!");
        }
    });
}

使用GCD下载图片(二)运行结果


你可能感兴趣的:(image,图片)