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