iOS中 target的使用


1
- (void)objectThread{ 2 Person *p = [Person new]; 3 //target 的作用: 不是碰到target 就写 self , 如果参数有方法, 那么这个target 就应该是实现该方法的对象(例如创建一个person类,需要用到类中的方法,这时就 要创建一个person类的对象p来代替self) 4 //注意: 一般情况下是self , 那是因为我们要执行的方法, 一般都写在当前类中所以写self 5 6 //创建阶段 7 NSThread *thread = [[NSThread alloc]initWithTarget:p selector:@selector(longTime) object:nil]; 8 //就绪阶段 线程什么时候开始执行 由系统调用 程序员无法用代码控制 9 [thread start]; 10 }
posted @ 2016-07-01 21:46  爱分享爱生活  阅读(271)  评论(0编辑  收藏  举报