简体   繁体   中英

Double Clicking on UITabBarControllers Tab goes to root of Navigation controller

I have a UITabBarController setup with 2 UINavigationControllers.

One UINavigationController has One UIViewController, the other UINavigationController has Two UIViewControllers. If you then navigate to the second UIViewController and click the Tab that is already selected it bring you to the root of the UINavigationController (This would be the first UIViewController).

Is there a way to stop this from happening? I do not want the user to be able to click an already selected Tab to go to the root of the Navigation Controller.

To do this you need to implement a function in your app delegate to pick up the tabbar delegate calls.

In your app delegate.m file, in the didfinishlaunching method, add this line

[tabBarController setDelegate:self];

then implement this method (also in your app delegate):

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

This gets called as part of the tab delegate protocol and will stop the selection of a tab if its already the selected one.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM