NSThread基本使用

来源:互联网 发布:淘宝网卖家客服电话 编辑:程序博客网 时间:2024/06/04 19:33
/* 第一种创建线程的方式 特点:需要调用start方法开启线程 */-(void)createThread1{        /*     第一个参数:目标对象     第二个参数:选择器,调用哪个方法     第三个参数:前面方法需要传递的参数     */        //创建线程    NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(run:) object:nil];    //设置基本属性    thread.name = @"线程1";        //线程优先级    [thread setThreadPriority:1.0];        //开启线程    [thread start];    }

/* 第二种创建线程的方式 特点:默认开启线程 */-(void)createThread2{    /*     第一个参数:选择器,调用哪个方法     第二个参数:目标对象     第三个参数:前面方法需要传递的参数     */    [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"wendingding"];}


/* 第三种创建线程的方式 特点:默认开启线程 */-(void)createThread3{    [self performSelectorInBackground:@selector(run:) withObject:@"后台线程"];}


0 0