I will accept answers in both swift and objective-c as the translation is fairly easy.
I want to display a tab bar with a splash screen, but I don't want that splash screen to be in the tab bar items for selection.
My setup now (below) shows the landing screen as the first displayed controller when the tab bar displays. However, I want that tab bar item hidden. Only the other three tabs should be selectable by a user. How do I do this?
//Create and add landing view
navigation = UINavigationController()
landingView = WGMLandingViewController(nibName: XIBFiles.LANDINGVIEW, bundle: nil)
navigation.pushViewController(landingView, animated: false)
navigation.title = "Landing View"
controllers.append(navigation)
//Create and add library view
navigation = UINavigationController()
libraryView = WGMLibraryViewController(nibName: XIBFiles.LIBRARYVIEW, bundle: nil)
navigation.pushViewController(libraryView, animated: false)
navigation.title = "Learn More"
controllers.append(navigation)
//Create and add pad view
navigation = UINavigationController()
orderPadView = WGMOrderPadViewController(nibName: XIBFiles.ORDERPADVIEW, bundle: nil)
navigation.pushViewController(orderPadView, animated: false)
navigation.title = "Order Pad"
controllers.append(navigation)
//Create and add lookup view
navigation = UINavigationController()
partLookupView = WGMLookupViewController(nibName: XIBFiles.LOOKUPVIEW, bundle: nil)
navigation.pushViewController(lookupView, animated: false)
navigation.title = "Lookup"
controllers.append(navigation)
//Set up controller list
self.setViewControllers(controllers, animated: false)
Apple's existing APIs don't allow you to do this, but we it shouldn't too hard to sub-class UITabBarController
and get it to do what you want.
Ok.. my original answer won't work these days.. or I've gone senile and it never worked and I did something else. *cough*
So anyway, you'll have to roll your own tab bar controller. It's not so hard (just time consuming) now that we have containment view controllers and you can still use the UITabBar
.
UIViewController
(your tab bar controller) and stick a UITabBar
and a UIView
in it.UITabBar
however you'd like it.delegate
of the UITabBar
to be your view controller and implement the didSelectItem
method.viewDidLoad
or where you want it.Something like
- (void)loadSplashScreen {
// load in the child view controller
UIViewController *splashScreenController = ...;
[self loadChildViewController:splashScreenController];
// make sure nothing in the tab bar is selected
self.tabBar.selectedItem = nil;
}
Then also add code to load the appropriate view controller whenever the various tabs are selected
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
// logic to figure out which view controller you want based on `item`
// ...
UIViewController = ...;
[self loadChildViewController:viewController];
}
- (void)loadChildViewController:(UIViewController *)viewController {
[self removeCurrentTabController]; // remove the existing one, if any using whatever memory management techniques you want to put in place.
[self addChildViewController:viewController];
[self.tabView addSubview:viewController.view]; // where self.tabView is your outlet from step 2.
}