iOS執行緒通訊
阿新 • • 發佈:2018-12-18
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
UIImage*image=[UIImage imageWithData:data];
[self performSelectorOnMainThread:@selector(downLoadDone:) withObject:image waitUntilDone:NO];
}
-(void)downLoadDone:(
{
NSLog(@"currentThread2=%@",[NSThread currentThread]);
self.imageView.image=image;
}