美文网首页
NSThread的四种创建方法

NSThread的四种创建方法

作者: 笑熬齊澄 | 来源:发表于2017-12-11 19:21 被阅读7次

//方式1  创建线程

NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(demo) object:nil];

//手动开启

[thread start];

//方式2  创建线程并启动线程

[NSThread detachNewThreadSelector:@selector(demo) toTarget:self withObject:nil];

//方式3 创建线程

[self performSelectorInBackground:@selector(demo) withObject:nil];

//方式4 创建线程执行带参数的方法

NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(demo:) object:@"aabb"];

[thread start];

}

- (void)demo:(NSString *)param {

NSLog(@"hello %@",param);

}

//线程执行的方法

- (void)demo {

NSLog(@"hello %@",[NSThread currentThread]);

}

相关文章

  • iOS 多线程 pthread & NSthread

    pthread NSthread 创建线程的四种方法 alloc initwith..|detachNewThre...

  • NSThread

    NSThread 创建线程 代码实现(创建线程的四种方法)创建线程的第一种方法:1.创建线程对象[[NSThrea...

  • 多线程-NSThread

    多线程学习笔记 - NSThread NSThread的集中创建方法 1.方法一: NSThread对象创建 需要...

  • 多线程 NSThread

    一 NSThread的基本使用1)NSThread创建的四种方式第一种 创建方式alloc initwith .....

  • 多线程 NSThread

    一 NSThread的基本使用 1)NSThread创建的四种方式 第一种 创建方式 alloc initwith...

  • NSThread的四种创建方法

    //方式1 创建线程 NSThread *thread = [[NSThread alloc] initWithT...

  • iOS 多线程详解

    一、NSThread 1、创建方法三种 ... /** 方法一,需要start */ NSThread*threa...

  • 多线程

    多线程 进程和线程 NSThread 通过类方法开启线程 通过NSObject的NSThread类别方法创建 注意...

  • iOS-多线程-NSThread

    一. NSThread的创建方式 1. 类方法创建 类方法创建不需要手动开启线程 2. 实例方法创建 实例方法创建...

  • 实现多线程的方法有哪些?

    开发的常用四种方式有 pthread 、 NSThread、GCD、NSOperation。下面是对这四种方法进行...

网友评论

      本文标题:NSThread的四种创建方法

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