how to get the event that switch tab menu on iphone

后端 未结 5 2325
星月不相逢
星月不相逢 2020-12-03 17:03

I\'m trying to figure out how to catch the event that controls the switch tabs on the UITabBarController. How could I accomplish this?

5条回答
  •  渐次进展
    2020-12-03 17:36

    Implement UITabBarControllerDelegate e.g. in your app delegate's applicationDidFinishLaunching

    - (void)applicationDidFinishLaunching:(UIApplication *)application
    {
        tabBarController.delegate = self;
        [window addSubview:tabBarController.view];
    }
    

    Then implement either:

    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
    
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
    

    The first method is called before the view switch and gives you a chance to 'veto' the view switch by returning NO

    The second method is called after the view switch has taken place

提交回复
热议问题