Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In iOS7 UITabbarController, how to stop resetting the navigationController to root on tapping the already selected tabBarItem?

I have a UITabBarController as the rootViewController in the storyboard of an iPad app.

It contains 3 tabBarItems.

Each item holds a navigationController.So total 3 navigationControllers.

Scenario:

  1. I select the 2nd tabBarItem. Then the 2nd navigationController will become visible on the tabBarController with the view of its associated rootController.

  2. I push some controllers on this visible navigationController.

  3. Now, when I tap of the 2nd tabBarItem ( which is already selected now ), the tabBarController pops-up all the pushed controllers and brings the navigationController to its rootController view.

Question: How can I stop this behaviour ? A selected tabBarItem should not do any action when the user taps on it again.

like image 434
CodenameLambda1 Avatar asked Jan 27 '26 03:01

CodenameLambda1


1 Answers

If you init the UITabBarController in rootViewController add UITabBarControllerDelegate in rootViewController, and implement this delegate:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    UIViewController* selected = [tabBarController selectedViewController];

    if (viewController == selected)
        return NO;
    else
        return YES;
}
like image 54
Javi Campaña Avatar answered Jan 29 '26 18:01

Javi Campaña



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!