如何等到嵌套的block执行完后再执行其他代码
1个回答
展开全部
这样就能等到 3个请求都返回数据以后再刷新 ,上面这种方法 属于 手动管理gourp 还有一种是 交给系统来管理:
例如:
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
dispatch_group_t group1 = dispatch_group_create();
dispatch_group_async(group1, queue, ^{
NSLog(@"A买水果");
});
dispatch_group_async(group1, queue, ^{
NSLog(@"B买烤鸭");
});
dispatch_group_async(group1, queue, ^{
NSLog(@"C买扑克");
});
dispatch_group_async(group1, queue, ^{
NSLog(@"D买水");
});
dispatch_group_notify(group1, queue, ^{
NSLog(@"Let's go!");
});
例如:
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
dispatch_group_t group1 = dispatch_group_create();
dispatch_group_async(group1, queue, ^{
NSLog(@"A买水果");
});
dispatch_group_async(group1, queue, ^{
NSLog(@"B买烤鸭");
});
dispatch_group_async(group1, queue, ^{
NSLog(@"C买扑克");
});
dispatch_group_async(group1, queue, ^{
NSLog(@"D买水");
});
dispatch_group_notify(group1, queue, ^{
NSLog(@"Let's go!");
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询