首页 > 移动平台 > 详细

iOS--线程的创建

时间:2017-06-14 22:52:38      阅读:344      评论:0      收藏:0      [点我收藏+]

1.获取当前线程

     NSThread *current=[NSThread currentThread]; 

2.
获取主线程的另外一种方式
     NSThread *main=[NSThread mainThread]; 
3.创建一个新的线程
(1)直接创建
     NSThread  *thread=[[NSThread alloc]initWithTarget:self selector:@selector(run:) object:@"线程A"];
     //为线程设置一个名称
     thread.name=@"线程A";
      //开启线程
     [thread start];

(2)创建完线程自动启动

 //    NSThread *thread=[NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"创建完线程直接(自动)启动"];
     [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"创建完线程直接(自动)启动"];

(3)隐式创建

      //在后台线程中执行===在子线程中执行
     [self performSelectorInBackground:@selector(run:) withObject:@"隐式创建"];

 

 


iOS--线程的创建

原文:http://www.cnblogs.com/huadeng/p/7011392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!