Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable tab bar navigating to root view

I have a tab bar based application with navigation on each tab bar item. When i navigate to another view on any tab bar item and click on on tab bar item,then root view controller on that tab bar item is called. Its like PopToRootView . Can we disable this situation?

like image 446
Himanshu Avatar asked Jan 13 '10 13:01

Himanshu


2 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 to: Disable action - user taps on tabbar item to go to root view controller

like image 174
Leigh McCulloch Avatar answered Sep 19 '22 14:09

Leigh McCulloch


Though they say you're not supposed to subclass UINavigationController, you can what you want by making a subclass of UINavigationController and overriding the - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated; method.

Doing this (and not calling the super popToRootViewController) will prevent the view controllers from popping when you click the tab bar item. It could run you into some problems somehow, but hopefully it works for you.

like image 29
mjdth Avatar answered Sep 23 '22 14:09

mjdth