views:

2269

answers:

3

I'm trying to programatically select/change the tab of the UITabViewController.

I tried doing it via:

self.tabBarController.selectedIndex = 2;

This looks to be the way that I should do it, but it doesn't work. I thought that maybe the self.tabBarController returns a read only object (I sorta remember reading that somewhere), but I'm not sure how to get it to work.

Any help is appreciated!

+6  A: 

Set selectedViewController:

self.tabBarController.selectedViewController = viewControllerYouWant;

For example,

self.tabBarController.selectedViewController 
    = [self.tabBarController.viewControllers objectAtIndex:2];
DasBoot
A: 

According to the docs, selectedIndex or selectedViewController are the properties you want and are both assignable.

The tabBarController property is readonly, but it returns an object that is editable.

So all your code looks right to me.

Squeegy
A: 

I'm doing something like this:

[root setSelectedViewController: [root.historyController navController]];
Steve918