Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push another view controller into a UITabBarController view

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?

like image 527
Aron K. Avatar asked Sep 09 '11 14:09

Aron K.


People also ask

How do I add a view controller to my navigation controller?

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 .

How do I embed a view 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.


1 Answers

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];
like image 174
Javier Soto Avatar answered Oct 16 '22 17:10

Javier Soto