Disable tab bar moving to root mode

I have a tabbar-based application with navigation for each tab bar item. When I switch to another view in any element of the tab bar and click on the tab bar element, the root view controller in that tab bar element is called. This is similar to PopToRootView. Can we turn this situation off?

+6
iphone uitabbarcontroller uinavigationcontroller
source share
4 answers

Yes, you can disable the automatic popToRootViewController by implementing the UITabBarControllerDelegate method on your view controller:

 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { if(self.navigationController == viewController) { return NO; } return YES; } 

Thanks: Disable the action - debug the user in the scoreboard element to go to the root view controller

+6
source share

Although they say you should not subclass UINavigationController , you can do what you want by creating a subclass of UINavigationController and overriding the - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated; .

Performing this action (and not calling the superthread) will not allow view controllers to appear when you click an item in the tab bar. This may lead to some problems, but hopefully this works for you.

+3
source share
  • Include UITabBarControllerDelegate in your header file.
  • try the following:

     - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { if(bool_youDontWantPopToRootView) return (tabBarController.selectedViewController != viewController); return YES; } 

For bool_youDontWantPopToRootView, you can add a condition to it if you want it to behave as the default behavior.

+2
source share

- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated; when you pass "NO" in the animated argument, you will be redirected to root mode without animation

you don’t need to use this method while you click on any tab bar your default navigation controller behavior that supports the native VC stack

+1
source share

All Articles