美文网首页iOS常用iOS大咖说
iOS如何动态控制tabBar上的Item

iOS如何动态控制tabBar上的Item

作者: Tomous | 来源:发表于2020-12-18 10:44 被阅读0次

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

    本文链接:https://www.haomeiwen.com/subject/aajxnktx.html