Selecting an UITabBarItem in the “More…” section

December 19, 2008 – 11:34 Share on Twitter

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.

  1. 3 Responses to “Selecting an UITabBarItem in the “More…” section”

  2. 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!

    By Jason Miller on Dec 23, 2008

  3. Where to call this method??

    Inside “didSelectViewController”??

    By Rocket on Aug 16, 2010

  4. 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

    By Stephan on Aug 22, 2010

Post a Comment