iphone app - detect which tab bar item was pressed

后端 未结 7 1136
我寻月下人不归
我寻月下人不归 2020-12-10 02:16

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

7条回答
  •  半阙折子戏
    2020-12-10 02:43

    1. So if you are using a UITabBarController you can make the class implement the UITabBarControllerDelegate and set your UITabBarController delegate to the class that needs to be notified when the TabBar selected item changes, then add the delegate method to your class:

    -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    

    Inside this method you can use the UITabBarController selectedIndex property to know which is the current index selected:

    -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:      (UIViewController *)viewController
    {
        NSLog(@"Selected index: %d", tabBarController.selectedIndex);
    }
    

    2. If you are not using just the UITabBar you can follow the answer here by Ken Pespisa and iCoder in this post Ken Pespisa and iCoder in this post.

提交回复
热议问题