多线程, 线程队列

10 篇文章 0 订阅
7 篇文章 0 订阅

  

多线程的使用(1)-performSelectorOnMainThread

 

[self performSelectorOnMainThread:@selector(RefreshCellForLiveId:)

                               withObject:userinfo

                            waitUntilDone:YES];



该方法的作用是在主线程中,执行制定的方法(代码块)。

参数:

@selector(RefreshCellForLiveId:)就是,要定义我们要执行的方法。

withObject:userinfo

定义了,我们执行RefreshCellForLiveId:方法时,传入的参数对象。类型是id。(我们可以传入任何参数)

waitUntilDone:YES];

指定,当前线程是否要被阻塞,直到主线程将我们制定的代码块(RefreshCellForLiveId:方法)执行完。

 //线程队列

 dispatch_group_t taskGroup =dispatch_group_create();//创建一个调度组

    dispatch_queue_t mainQueue =dispatch_get_main_queue();//创建队列

    dispatch_group_async(taskGroup, mainQueue, ^{

NSLog(@"方法一");

    });

    dispatch_group_async(taskGroup, mainQueue, ^{

NSLog(@"方法二");

    });


    dispatch_group_async(taskGroup, mainQueue, ^{

NSLog(@"方法三");

    });


    dispatch_group_notify(taskGroup, mainQueue, ^{

NSLog(@"最后执行");

    });

    dispatch_release(taskGroup);


//多线程,异步获取图片

//异步获取图片

//UIImageView * la1 = (UIImageView*)[self.view viewWithTag:85521];

//dispatch_queue_t queue;

//queue = dispatch_queue_create("com.example.operation", NULL);

//dispatch_async(queue, ^{

//    NSData * imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:IMAGE]]];

//    UIImage *imge = [UIImage imageWithData:imageData];

//    

//    dispatch_async(dispatch_get_main_queue(), ^{

//        la1.image = imge;

//    });

//    

//});




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值