美文网首页
iOS线程间通信 - NSThread篇

iOS线程间通信 - NSThread篇

作者: 小码honey | 来源:发表于2020-07-20 11:33 被阅读0次

线程间通信常用方法:

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait;

- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait;

开子线程下载数据,在主线程刷新UI;

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
   //NSOperation 篇
//    [self downLoadImageAndShow];
//NSThread 篇
    [self performSelectorInBackground:@selector(downLoad) withObject:nil];
}

#pragma mark - //NSThread 篇
- (void)downLoad{
    NSURL * url = [NSURL URLWithString:@"https://zuoye2.xinkaoyun.com/awm/35/iOS_09060620200720110101.jpeg"];
    NSData * data = [NSData dataWithContentsOfURL:url];
    UIImage * image = [UIImage imageWithData:data];
    [self performSelectorOnMainThread:@selector(iconSetImage:) withObject:image waitUntilDone:NO];
   
}

- (void)iconSetImage:(UIImage *)image{
    self.iconImageView.image = image;
}

子线程下载图片

相关文章

  • iOS多线程篇:NSThread

    iOS多线程篇:NSThread iOS多线程篇:NSThread

  • iOS线程间通信 - NSThread篇

    线程间通信常用方法: - (void)performSelectorOnMainThread:(SEL)aSele...

  • iOS - 线程 / 进程 的通信

    1. 线程中的通信 线程中通信的体现 在iOS多线程开发中,有NSThread、GCD、NSOpeartion几种...

  • 《iOS高级开发之多线程编程之二》

    线程间的通信 在一个进程中,线程往往不是孤立存在的,多个线程之间经常进行通信,称为线程间通信。 NSThread ...

  • NSThread线程间通信

    线程间通信:1.一个线程传递数据给另一个线程 2.一个线程执行完任务后转到下一个线程继续执行任务。 常用方法: -...

  • 线程间的通信

    1>NSThread的线程间的通信将一个线程执行的结果, 传到另外一个线程 (不同的线程之间的通信都是线程通信)S...

  • iOS线程之间的通信

    线程间通讯 一、NSThread 1.简单说明 ①线程间通信:在1个进程中,线程往往不是孤立存在的,多个线程之间需...

  • iOS 多线程

    iOS使用线程的方式 pthread NSThread GCD NSOperation NSThread线程的创建...

  • iOS多线程(三)-NSThread

    iOS多线程(二)-NSThread

  • OC_NSThread

    原文链接:iOS多线程--彻底学会多线程之『pthread、NSThread』 **NSThread **是苹果官...

网友评论

      本文标题:iOS线程间通信 - NSThread篇

      本文链接:https://www.haomeiwen.com/subject/zsuekktx.html