R – Disable tab bar navigating to root view

iphoneuinavigationcontrolleruitabbarcontroller

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?

Best Answer

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