xcode 回到导航控制器在 TabBar 应用程序中的第一个视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9452688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:26:39  来源:igfitidea点击:

Back to Navigation Controller's first view in TabBar app

iosxcodeuinavigationcontrolleruitabbarcontrolleruitabbar

提问by Eugene Trapeznikov

I got a tabbar application.

我有一个标签栏应用程序。

There is only 2 tabs in the tabbar. First tab is a NavigationController, there are two views in the NavigationController- root and detail views, second is a TableViewController. Second works perfect, but the the first doesn't.

标签栏中只有 2 个标签。第一个选项卡是 a NavigationController,在NavigationController- 根视图和详细视图中有两个视图,第二个是TableViewController. 第二个工作完美,但第一个没有。

I start in first view (NavigationController). Then go in this NavigationViewto the detail view. Then, for example, i go to the second tabbar view. Then go back to the first, but i dont see the root view, but the detail view.

我从第一个视图 ( NavigationController) 开始。然后进入NavigationView详细视图。然后,例如,我转到第二个标签栏视图。然后回到第一个,但我没有看到根视图,而是详细视图。

How can i open the root view every time?

如何每次都打开根视图?

回答by dom

Use the UITabBarController delegatemethod tabBarController:didSelectViewController:like this:

像这样使用UITabBarController 委托方法tabBarController:didSelectViewController:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  if (viewController != tabBarItemForNavControllerTab) {
    [self.navControllerInFirstTab popToRootViewControllerAnimated:NO];
  }
}

Also make sure that delegate is setup properly, when creating your UITabBarControllerand you change the code from my snippet to fit your controller names.

还要确保在创建时正确设置了委托,UITabBarController并且您更改了我的代码段中的代码以适合您的控制器名称。