动态显示、影藏其中某个tabBarItem

关键代码

显示

//显示
    TabBarController *tabBarController = (TabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [tabBarController viewControllers]];
    ViewController2 * threeVc = [ViewController2 new];
    threeVc.title = @"三";
    threeVc.tabBarItem.image = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    threeVc.tabBarItem.selectedImage = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 为子控制器包装导航控制器
    UINavigationController * navigationVc = [[UINavigationController alloc] initWithRootViewController:threeVc];
    [tabbarViewControllers insertObject:navigationVc atIndex:2];
    [tabBarController setViewControllers: tabbarViewControllers];

影藏

//隐藏
    TabBarController *tabBarController = (TabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [tabBarController viewControllers]];
    [tabbarViewControllers removeObjectAtIndex:2];
    [tabBarController setViewControllers: tabbarViewControllers];
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容