Search code examples
objective-ctabbaruitabbaritem

iphone app - detect which tab bar item was pressed


i have a tab bar based application, with more than 5 tab bar items - so i get 4 of them directly showing in the view and the rest available by selecting the "More" tab. When a tab bar item is pressed, i want to detect which one was it.
So, in the
- (void)tabBarController:(UITabBarController *)tabBarCtrl didSelectViewController:(UIViewController *)viewController method, i use tabBarCtrl.selectedViewController.title to get the item's title.

This works for the tabs visible in the view -that is the 4 first and the "More" tab- but does not work for the rest of my tab bar items which are shown in the list after pressing the "More" tab.

I can see that the didSelectViewController method is not even called when selecting a tab from the "More" list.
How can i detect any of them when pressed?

Thank you in advance.


Solution

  • How to get title of UITabBarItem in the More section?

    - (void)tabBarController:(UITabBarController *)tabBarController 
     didSelectViewController:(UIViewController *)viewController
    {
        NSLog(@"controller class: %@", NSStringFromClass([viewController class]));
        NSLog(@"controller title: %@", viewController.title);
    
        if (viewController == tabBarController.moreNavigationController)
        {
            tabBarController.moreNavigationController.delegate = self;
        }
    }