双击UITabBarControllers选项卡转到导航控制器的根目录

Mau*_*imo 6 iphone uitabbarcontroller uinavigationcontroller ios

我有一个UITabBarController设置与2 UINavigationControllers.

一个UINavigationController有一个UIViewController,另一个UINavigationController有两个UIViewControllers.然后,如果您导航到第二个UIViewController并单击已选中的选项卡,它会将您带到UINavigationController的根目录(这将是第一个UIViewController).

有没有办法阻止这种情况发生?我不希望用户能够单击已选择的选项卡以转到导航控制器的根目录.

Tim*_*alf 20

为此,您需要在应用程序委托中实现一个函数来获取tabbar委托调用.

在您的app delegate.m文件中,在didfinishlaunching方法中,添加此行

[tabBarController setDelegate:self];
Run Code Online (Sandbox Code Playgroud)

然后实现此方法(也在您的app委托中):

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

这将作为选项卡委托协议的一部分进行调用,如果选项卡已经选中,则将停止选择选项卡.

希望有所帮助.