GCD高级编程例子

来源:互联网 发布:数据库开发工程师简历 编辑:程序博客网 时间:2024/09/21 09:24

两种方法,实现一件事情做完,再做另外一件事情。 

1、

dispatch_async(dispatch_get_main_queue(), ^{

[self.navigationController popToRootViewControllerAnimated:NO];

});

            

dispatch_barrier_async(dispatch_get_main_queue(), ^{

[[[AppDelegate getDelegatetabbarControllersetSelectedIndex:0];

});

 

2、

dispatch_group_t group =dispatch_group_create();

            

dispatch_group_async(group,dispatch_get_main_queue(), ^{

[self.navigationControllerpopToRootViewControllerAnimated:NO];

});

            

dispatch_group_notify(group,dispatch_get_main_queue(), ^{

[[[AppDelegategetDelegate]tabbarController]setSelectedIndex:0];

});


出现问题的代码如下:

[self.navigationController popToRootViewControllerAnimated:NO];

[[[AppDelegate getDelegatetabbarControllersetSelectedIndex:0];

由于导航控制器里面的子控制器比较多,第一句话执行的时间比较长,当第二句执行完时,第一句还没有执行完。导致再次切换tabbarController时出现崩溃的现象。
1 0
原创粉丝点击