Search code examples
iphoneuitabbar

Selected index on the "more" view of a UITabbar


How can I manage the user selection on the "more" view of a UITabBar? I have this code to manage the UITabBarItems selections:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {    
    if (!(viewController == tabBarController.moreNavigationController)) {
        int index = tabBarController.selectedIndex;
        [[DataManager sharedInstance] setCurrentTabbarIndex:index];
    }
}

It works fine for the visible UITabBarItems, but when the user select some item from the "more" view I never get informed about that. Is there some way to catch the user item selection of the "more" view? Thanks!


Solution

  • The "more" view of a UITabBarController is handled separately from the other views. Apple's discussion on this subject says the following:

    [The 'moreNavigationController'] property always contains a valid More navigation controller, even if a More button is not displayed on the screen. You can use the value of this property to select the More navigation controller in the tab bar interface or to compare it against the currently selected view controller.

    Do not add the object stored in this property to your tab bar interface manually. The More controller is displayed automatically by the tab bar controller as it is needed. You must also not look for the More navigation controller in the array of view controllers stored in the viewControllers property. The tab bar controller does not include the More navigation controller in that array of objects.

    Judging from that I would think that you can do something like:

    int index = tabBarController.selectedIndex;
    if (tabBarController.selectedViewController == 
        tabBarController.moreNavigationController) {
        index = -1;  //assign some placeholder index for the "More" controller
    }