For the navigation in my app I'm using a UITabBarController. This works fine, but in one of my viewcontrollers I want to push another view controller into the tabbar view. In other words I want to replace the selected viewcontroller with another one. I'm doing this with the following code:
self.tabBarController.selectedViewController = self.otherViewController;
The list of viewControllers in my TabBarController does not contain the otherViewController. This trick works fine in IOS 4.3, but IOS 5 does not like it.
Does anyone know a solution which is accepted by IOS 5?
Step 1: Embed root view controller inside a navigation controller. In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .
Just drag a container view out into your main view controller and use the embed segue from it to your embedded view controller. It will properly set up all the view controller hierarchy for you.
You want to REPLACE that view controller in the tabbar with another view Controller? If so, you have to edit the viewControllers property in the tabbar by setting a new one. It would be something like:
UIViewController *thisIsTheViewControllerIWantToSetNow;
int indexForViewControllerYouWantToReplace;
NSMutableArray *tabbarViewControllers = [self.tabbar.viewControllers mutableCopy];
[tabbarViewControllers replaceObjectAtIndex:indexForViewControllerYouWantToReplace withObject:thisIsTheViewControllerIWantToSetNow];
self.tabbar.viewControllers = tabbarViewControllers;
[tabbarViewControllers release];
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