自定义一个Operation
start用来检查
代码下载main
继承他们的父类
-(void)start{
NSLog(@"%s %@",__func__,[NSThread currentThread]);
[super start];
NSLog(@"%s %@",__func__,[NSThread currentThread]);
[super start];
}
使用代理
-(void)main{
NSLog(@"%s %@",__func__,[NSThread currentThread]);
@autoreleasepool {
NSString *imgAddr = @"http://attachments.gfan.com/forum/attachments2/day_121023/1210232138c4878e8a7973a2d4.jpg";
NSURL *url = [NSURL URLWithString:imgAddr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
//线程间的通信
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if(self.delegate){
if([self.delegate respondsToSelector:@selector(downloadIMGOperationDelegateFinish:)]){
[self.delegate downloadIMGOperationDelegateFinish:image];
}
}
}];
}
NSLog(@"%s %@",__func__,[NSThread currentThread]);
@autoreleasepool {
NSString *imgAddr = @"http://attachments.gfan.com/forum/attachments2/day_121023/1210232138c4878e8a7973a2d4.jpg";
NSURL *url = [NSURL URLWithString:imgAddr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
//线程间的通信
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if(self.delegate){
if([self.delegate respondsToSelector:@selector(downloadIMGOperationDelegateFinish:)]){
[self.delegate downloadIMGOperationDelegateFinish:image];
}
}
}];
}
}