I have an application that needs to show different content from a UITabBarController
based on if the user is registered or not. Is there a way to add and remove ViewController
s from a UITabBarController
at run-time? 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.
You can remove a tabbar item as follows:
NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [self.tabBarController viewControllers]];
[tabbarViewControllers removeObjectAtIndex: /*Any index*/];
[self.tabBarController setViewControllers: tabbarViewControllers ];
Swift 4+
func removeTab(at index: Int) {
guard var viewControllers = self.tabBarController?.viewControllers else { return }
viewControllers.remove(at: index)
self.tabBarController?.viewControllers = viewControllers
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With