I needed to select an UITabBarItem located in the « More… » section, and I came to this solution:
To select a viewController of the tabBarController, I do the following (each tabBarItem has a tag) :
- (IBAction) showAnotherTab:(id)sender
{
int tag = [sender tag];
NSArray *viewControllers = [self.tabBarController viewControllers];
for (int i=0; i<[viewControllers count]; i++) {
int tabTag = [[[viewControllers objectAtIndex:i] tabBarItem] tag];
if (tag == tabTag) {
if (i < 4) {
[self.tabBarController setSelectedIndex:i];
} else {
[self.tabBarController.moreNavigationController
popToRootViewControllerAnimated:NO];
[self.tabBarController setSelectedIndex:4];
[self performSelector:@selector(selectMore:)
withObject:[viewControllers objectAtIndex:i]
afterDelay:0.0f];
}
}
}
}
//=====================================
- (void) selectMore:(UIViewController *)controller
{
[self.tabBarController.moreNavigationController
pushViewController:controller animated:NO];
}
This method is not perfect, since when you will see the « More… » navigationController flash before the new tabBar is displayed. I suppose that doing this in a modal should do the trick.
Thanks for posting this! I just ran into this very issue and this post was the first page I found, after a good bit of googling, to actually talk about this issue. Your code worked for me!
Where to call this method??
Inside « didSelectViewController »??
No, you call this method when you need to select a specific tabBar item. In my case, I have a screen with different icons, like the dashboard, and touching an icon selects a tabBar item. You can see this working in this app: http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=307368454&mt=8