how to get the event that switch tab menu on iphone

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


If you are using storyboard, do this

in didFinishLaunchingWithOptions

UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setDelegate:self];

Also in AppDelegate, keep <UITabBarControllerDelegate>

And then

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
   //Write your code here
}