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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.