1、线程通信的概念
1)一个线程传递数据给另一个线程;
2)在一个线程中执行完特定任务后,转到另一个线程继续执行任务;
2、实例
图片下载显示:
- (IBAction)add:(id)sender {
[self performSelectorInBackground:@selector(downLoad) withObject:nil];
}
- (IBAction)delet:(id)sender {
self.imageView.image=nil;
}
-(void)downLoad
{
NSString*urlStr=@"http://www.0739i.com.cn/data/attachment/portal/201603/09/120156l1yzzn747ji77ugx.jpg";
NSData*data=[NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
UIImage*image=[UIImage imageWithData:data];
[self performSelectorOnMainThread:@selector(downLoadDone:) withObject:image waitUntilDone:NO];
}
-(void)downLoadDone:(UIImage*)image
{
NSLog(@"currentThread2=%@",[NSThread currentThread]);
self.imageView.image=image;
}