Double Clicking on UITabBarControllers Tab goes to root of Navigation controller

守給你的承諾、 提交于 2019-12-22 05:42:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4856159/double-clicking-on-uitabbarcontrollers-tab-goes-to-root-of-navigation-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!