xcode 使用故事板时从 UITabbarController 添加/删除或显示/隐藏标签栏项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13403247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:06:41  来源:igfitidea点击:

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

iosxcodeuitabbarcontroller

提问by Dennis Burton

I have an application that needs to show different content from a UITabBarControllerbased on if the user is registered or not. Is there a way to add and remove ViewControllers from a UITabBarControllerat run-time? Show and Hide would be fine too.

我有一个应用程序需要UITabBarController根据用户是否注册来显示不同的内容。有没有办法在运行时ViewController从 a添加和删​​除s UITabBarController?显示和隐藏也可以。

Prior to storyboards you could call setViewControllerbut that does not seem to be the right way when using stoaryboards.

在使用故事板之前,您可以调用,setViewController但在使用故事板时这似乎不是正确的方法。

回答by user427969

You can remove a tabbar item as follows:

您可以按如下方式删除标签栏项目:

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

回答by Maverick

Swift 4+

斯威夫特 4+

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

回答by NiranjanB

While designing in storyboard we can hide the tab bar using the option Bottom-bar as nonein file-inspector.

在故事板中设计时,我们可以使用文件检查器中的底部栏选项隐藏标签栏。

enter image description here

在此处输入图片说明