iOS如何动态控制tabBar上的Item

如果是根据接口来的,那我的处理方法就是在首页的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) {
    }];

}

你可能感兴趣的:(iOS如何动态控制tabBar上的Item)