简体   繁体   English

使用故事板时,从UITabbarController添加/删除或显示/隐藏选项卡栏项

[英]Add/Remove or Show/Hide tab bar items from UITabbarController when using storyboards

I have an application that needs to show different content from a UITabBarController based on if the user is registered or not. 我有一个应用程序,需要根据用户是否注册来显示UITabBarController的不同内容。 Is there a way to add and remove ViewController s from a UITabBarController at run-time? 有没有办法在运行时从UITabBarController添加和删​​除ViewController Show and Hide would be fine too. 显示和隐藏也没关系。

Prior to storyboards you could call setViewController but that does not seem to be the right way when using stoaryboards. 在故事板之前,您可以调用setViewController但这在使用stoaryboards时似乎不是正确的方法。

You can remove a tabbar item as follows: 您可以删除tabbar项目,如下所示:

NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [self.tabBarController viewControllers]];
[tabbarViewControllers removeObjectAtIndex: /*Any index*/];
[self.tabBarController setViewControllers: tabbarViewControllers ];

Swift 4+ Swift 4+

func removeTab(at index: Int) {
        guard var viewControllers = self.tabBarController?.viewControllers else { return }
        viewControllers.remove(at: index)
        self.tabBarController?.viewControllers = viewControllers
    }

While designing in storyboard we can hide the tab bar using the option Bottom-bar as none in file-inspector. 在故事板中进行设计时,我们可以使用文件检查器中的Bottom-bar选项隐藏标签栏。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从UITabBarController场景中删除选项卡栏项 - Remove tab bar item from a UITabBarController scene iOS-如何使用动画隐藏/显示UITabBarController的选项卡栏? - iOS- How to Hide/Show UITabBarController's tab bar with animation? 推送UIViewController时隐藏UITabBarController的选项卡栏 - hide UITabBarController's tab bar when pushing UIViewController 在iOS中从UITabBarController移除标签栏的安全方法 - Safe way to remove tab bar from UITabBarController in ios 使用情节提要板ioS5时从视图控制器移动到选项卡栏控制器 - Moving from a view controller to a tab bar controller when using storyboards ioS5 具有UINavigationController的UITabBarController,在hidesBottomBarWhenPushed而不是UITabBarController选项卡栏上隐藏UINavigationController工具栏 - UITabBarController with UINavigationController, hide UINavigationController toolbar on hidesBottomBarWhenPushed, not UITabBarController tab bar ios:如何使用StoryBoards从ViewController打开Tab Bar控制器 - ios: How open Tab Bar controller from ViewController using StoryBoards UITabBarController 使用多个故事板 - UITabBarController using multiple storyboards 从UITabBarController调用时,无法在通用函数中获取选项卡项目 - Unable to get tab items in a common function when called from UITabBarController iOS10:使用UITabBarController()时隐藏状态栏 - iOS10: Hide status bar when using a UITabBarController()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM