Selecting an UITabBarItem in the « More… » section

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.

3 réflexions au sujet de “Selecting an UITabBarItem in the « More… » section”

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

Laisser un commentaire