dispatch_group_enter(group) 和dispathc_group_leave(group) 成对出现
_group = dispatch_group_create();
dispatch_queue_t queue = dispatch_get_main_queue();
dispatch_group_enter(_group);
[self getHomeLunboData:^{
dispatch_group_leave(self->_group);
}];
dispatch_group_enter(_group);
[self getHomeActivitysData:^{
dispatch_group_leave(self->_group);
}];
dispatch_group_notify(_group, queue, ^{
DGLog(@"处理headerview");
float he = ((DGSCREEN_WIDTH - Set_WidthScale(30.)) * 129 / 345);
[self.headerView configPics:self.lunboArrary notices:self.noticeListModelArray];
if (kArrayIsEmpty(self.lunboArrary)) {
if (kArrayIsEmpty(self.noticeListModelArray)) {
self.headerView.frame = CGRectMake(0, 0, self.view.width, he + 15 + [DGIconView getIconVH] + 10);
self.tableView.tableHeaderView = self.headerView;
}else{
[self.tableView.tableHeaderView changeHeight: 15 + [DGIconView getIconVH] + 10 + 48 + 10];
self.tableView.tableHeaderView = self.headerView;
}
}else{
if (kArrayIsEmpty(self.noticeListModelArray)) {
[self.headerView changeHeight:he + 15 + [DGIconView getIconVH] + 10];
self.tableView.tableHeaderView = self.headerView;
}else{
[self.headerView changeHeight:he + 15 + [DGIconView getIconVH] + 10 + 48 + 10];
self.tableView.tableHeaderView = self.headerView;
}
}
});
- (void)getHomeLunboData:(void(^)(void))returnBlock{
[[RequestAPIClient APIClientInstance] sendRequestPath:kGetLunbo params:@{} method:Post_Method success:^(id _Nonnull responseObject) {
if (200 == [responseObject[@"code"] integerValue]) {
[self.tableView.mj_header endRefreshing];
self.lunboArrary = [HZLunboModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
}
returnBlock();
} failure:^(id _Nonnull responseObject) {
DGLog(@"%@", responseObject);
returnBlock();
}];
}
- (void)getHomeActivitysData:(void(^)(void))returnBlock{
[[RequestAPIClient APIClientInstance] sendRequestPath:kGetNotices params:@{} method:Post_Method success:^(id _Nonnull responseObject) {
if (200 == [responseObject[@"code"] integerValue]) {
[self.tableView.mj_header endRefreshing];
self.noticeListModelArray = [DGHomeNoticeModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
}
returnBlock();
} failure:^(id _Nonnull responseObject) {
returnBlock();
}];
}