【问题标题】:iOS show tabbar only on NavigationController root [duplicate]iOS仅在NavigationController根目录上显示标签栏[重复]
【发布时间】:2019-10-03 19:18:31
【问题描述】:

视图控制器设置如下所示:

UITabBarController
  - Tab 1
    - UINavigationController
      - UITableViewController
        - select row pushes UIViewController (self.navigationController pushViewController)
          - select button pushes another UIViewController
  - Tab 2
    - UIViewcontroller

我的AppDelegate 应该反映上面的设置,看起来像这样:

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
  UITabBarController*     tabBarController           = [[UITabBarController     alloc] init];
  UITableViewController*  myListController           = [[MyListController       alloc] init];
  myListController.hidesBottomBarWhenPushed          = YES;
  UINavigationController* navigationControllerMyList = [[UINavigationController alloc] initWithRootViewController:myListController];
  navigationControllerMyList.tabBarItem              = [[UITabBarItem           alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];

  UIViewController* simpleViewController             = [[SimpleViewController   alloc] init];
  simpleViewController.tabBarItem                    = [[UITabBarItem           alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
  tabBarController.viewControllers                   = @[ navigationControllerMyList , simpleViewController ];

  self.window                    = [[UIWindow alloc] init];
  self.window.rootViewController = tabBarController;
  [self.window makeKeyAndVisible];

  return YES;
}

我面临的问题是,一旦我在表格视图控制器中选择了一行,标签栏就会按预期通过设置 myListController.hidesBottomBarWhenPushed = YES; 隐藏

UINavigationController 导航回标签栏不会再次显示,但我希望再次显示它。但前提是我位于导航控制器的根目录。

我尝试在UITableViewController 中将tabBar.hidden 设置为NO,但是一旦我导航回来并且tabBar 始终可见。

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
  self.tabBarController.tabBar.hidden = NO;
}

我还看到了this 的回答,基本上说我必须自己管理每个视图控制器中的标签栏。我尽量避免这种情况。

仅在导航控制器根目录中正确隐藏和显示标签栏我错过了什么?

【问题讨论】:

标签: ios objective-c uinavigationcontroller uitabbarcontroller


【解决方案1】:

在导航控制器中推送任何 VC 之前,只需添加一行 navigationController?.hideBottomBarWhenPushed = true

不要复制粘贴可能有语法错误,尝试输入xcode会给出建议。

【讨论】:

  • 感谢您的反馈。我看到您发布了我已经尝试使用的代码行。正如我所写的那样,它并没有给我想要的行为。我现在使用了我作为评论添加的方法。
猜你喜欢
  • 1970-01-01
  • 2021-09-04
  • 2012-01-20
  • 1970-01-01
  • 2017-08-14
  • 2018-02-02
  • 1970-01-01
  • 2014-12-17
相关资源
最近更新 更多