GCD多个接口请求完之后刷新UI
#pragma mark - 单个页面多个网络请求的情况(依次调用接口),等待所有网络请求结束后,再刷新UI
dispatch_group_enter(group)和dispatch_group_leave(group)组合使用
- (void)loadHttpData{
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t searialQueue = dispatch_queue_create("com.hmc.www", DISPATCH_QUEUE_SERIAL);
dispatch_group_enter(group);
dispatch_group_async(group, searialQueue, ^{
// 网络请求一
[WebRequest getDataSuccess:^(NSDictionary *dict) {
dispatch_group_leave(group);
} failure:^(NSError *err) {
dispatch_group_leave(group);
}];
});
dispatch_group_enter(group);
dispatch_group_async(group, searialQueue, ^{
// 网络请求二
[WebRequest getDataSuccess:^(NSDictionary *dict) {
dispatch_group_leave(group);
} failure:^(NSError *err) {
dispatch_group_leave(group);
}];
});
dispatch_group_enter(group);
dispatch_group_async(group, searialQueue, ^{
// 网络请求三
[WebRequest getDataSuccess:^(NSDictionary *dict) {
dispatch_group_leave(group);
} failure:^(NSError *err) {
dispatch_group_leave(group);
}];
});
三个网络请求结束后,会进入这个方法,在这个方法中进行界面的刷行
dispatch_group_notify(group, searialQueue, ^{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
// 刷新UI
});
});
});