开发者

Double Clicking on UITabBarControllers Tab goes to root of Navigation controller

I have a UITabBarController setup with 2 UINavigationControllers开发者_如何学JAVA.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜