Click another view controller in the UITabBarController view

For navigation in my application I use UITabBarController. This works great, but in one of my view controllers, I want to click another view controller in the view on the panel. In other words, I want to replace the selected viewcontroller with another. I am doing this with the following code:

self.tabBarController.selectedViewController = self.otherViewController; 

The viewControllers list in my TabBarController does not contain otherViewController. This trick works great on iOS 4.3, but he doesn't like iOS 5.

Does anyone know the decision made by iOS 5?

+7
source share
2 answers

Do you want to REPLACE this tab view controller with another view controller? If so, you need to edit the viewControllers property on the tab, setting a new one. It will be something like:

 UIViewController *thisIsTheViewControllerIWantToSetNow; int indexForViewControllerYouWantToReplace; NSMutableArray *tabbarViewControllers = [self.tabbar.viewControllers mutableCopy]; [tabbarViewControllers replaceObjectAtIndex:indexForViewControllerYouWantToReplace withObject:thisIsTheViewControllerIWantToSetNow]; self.tabbar.viewControllers = tabbarViewControllers; [tabbarViewControllers release]; 
+12
source

Can't you just use a navigation controller or the like on this tab?

In any case, this should work:

 NSMutableArray *controllers = [NSMutableArray arrayWithArray:rootTabBarController.viewControllers]; [controllers replaceObjectAtIndex:rootTabBarController.selectedIndex withObject: newController]; rootTabBarController.viewControllers = controllers; 
0
source

All Articles