多线程

151 阅读1分钟

NSThread 创建的三种方式:

     // 创建线程  object是传给方法的参数
        NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@"jack"];
        // 启动线程
        [thread start];
//不需要alloc  start 来创建子线程
[NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"rose"];
//不显示NSThread 来创建子线程
[self performSelectorInBackground:@selector(run:) withObject:@"jack"];