码迷,mamicode.com
首页 > 编程语言 > 详细

多线程知识点总结 -NSThread4

时间:2016-08-05 06:31:47      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

NSThread

 三种创建方式

NSThread的对象方法
- (void)threadDemo1 {
    NSLog(@"before %@", [NSThread currentThread]);

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

    [thread start];

    NSLog(@"after %@", [NSThread currentThread]);
}
小结:在start方法执行完毕后,会在另一个线程执longOperation:方法

 NSThread的类方法
- (void)threadDemo2 {
    NSLog(@"before %@", [NSThread currentThread]);

    [NSThread detachNewThreadSelector:@selector(longOperation:) toTarget:self withObject:@"DETACH"];

    NSLog(@"after %@", [NSThread currentThread]);
}
小结:detachNewThreadSelector:类方法不需要启动;会自动创建线程并执行@selector方法
NSThread的类方法
- (void)threadDemo3 {
    NSLog(@"before %@", [NSThread currentThread]);

    [self performSelectorInBackground:@selector(longOperation:) withObject:@"PERFORM"];

    NSLog(@"after %@", [NSThread currentThread]);
}
小结:这是NSObject的分类方法,会在后台自动执行@selector方法;




 




 

多线程知识点总结 -NSThread4

标签:

原文地址:http://www.cnblogs.com/bixiangbei/p/5739061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!