转载:http://www.cnblogs.com/wzh521/p/4823379.html
NSThread创建方式:
方式一:利用perform开启多线程,并且执行方法threadAction
2 [self performSelectorInBackground:@selector(threadAction) withObject:@"thread"];
3
4 方式二:
5 NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(threadAction:) object:@"text"];
6 thread.name = @"thread1";
7 //开启线程
8 [thread start];
9
10 //方式三:开启新的线程,并且执行
11 [NSThread detachNewThreadSelector:@selector(threadAction:) toTarget:self withObject:@"thread2"];
1 //获取当前线程
2 NSThread *thread = [NSThread currentThread];
3 //判断当前是否在多线程
4 [NSThread isMultiThreaded]
5 //判断当前是否在主线程
6 [NSThread isMainThread]
7 //让当前线程睡眠几秒
8 [NSThread sleepForTimeInterval:3];
9 //回到主线程
10 // [self performSelectorOnMainThread:<#(SEL)#> withObject:<#(id)#> waitUntilDone:<#(BOOL)#>]