iOS如何动态控制tabBar上的Item
2020-12-18 本文已影响0人
Tomous
如果是根据接口来的,那我的处理方法就是在首页的viewWillAppear方法里加载接口,动态来移除或者不移除tabBarController里面的VC
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// 控制质损模块是否隐藏
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[DCServiceTool postWithUrl:getLossState params:dic success:^(id responseObject) {
if ([responseObject[@"code"] integerValue] != 0) {
return;
}else{//responseObject[@"record"][@"flag"]
if (responseObject[@"record"][@"flag"]) {//显示
}else {//隐藏
DCTabBarViewController *tabBarController = (DCTabBarViewController *)[UIApplication sharedApplication].delegate.window.rootViewController;
NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [tabBarController viewControllers]];
[tabbarViewControllers removeObjectAtIndex:2];
[tabBarController setViewControllers: tabbarViewControllers ];
}
}
} failure:^(NSError *error) {
}];
}