标签:
//重写main方法
-(void)main
{
//创建自动释放池
@autoreleasepool {
//断言
NSAssert(self.finishedBlock != nil, @"finishedBlock 为nil");
NSLog(@"%@ %@",self.urlstr,[NSThread currentThread]);
//进行图片下载
//模拟网络延迟
[NSThread sleepForTimeInterval:2.0];
NSURL *url = [NSURL URLWithString:self.urlstr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [UIImage imageWithData:data];
//取消操作
if (self.isCancelled) {
return;
}
//图片下载完成
//更新ui回到主线程
[[NSOperationQueue mainQueue]addOperationWithBlock:^{
self.finishedBlock(img);
}];
}
}
标签:
原文地址:http://www.cnblogs.com/bong/p/5254382.html