iOS 仅在 NavigationController 根目录上显示选项卡栏

标签 ios objective-c uinavigationcontroller uitabbarcontroller

View Controller 设置如下所示:

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

我的AppDelegate应反射(reflect)上面的设置,如下所示:

- (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;
}

我面临的问题是,一旦我在 TableView Controller 中选择一行,选项卡栏就会按预期隐藏 myListController.hidesBottomBarWhenPushed = YES;

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

我尝试设置tabBar.hiddenNOUITableViewController但是一旦我导航回来,tabBar 总是可见的。

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

我还看到了this答案基本上是说我必须自己管理每个 View Controller 中的选项卡栏。我尽量避免这种情况。

仅在导航 Controller 根正确隐藏和显示选项卡栏时我错过了什么?

最佳答案

在将任何 VC 插入导航 Controller 之前,只需添加一行 navigationController?.hideBottomBarWhenPushed = true

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

关于iOS 仅在 NavigationController 根目录上显示选项卡栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56169785/

相关文章:

iphone - 动态 UITableViewCell 高度,延迟加载单元格中的图像

ios - Xamarin 绑定(bind)类别返回错误 : cannot declare instance members in a static class

swift - 展开后 TableView 消失

ios - 设置后退按钮 segue 的速度/动画

整个应用程序的 iOS 数据访问

ios - 在真实设备上调试 iAd 时变绿

objective-c - 为什么要使用类别而不是子类?

iphone - iOS Storyboard如何在没有导航 Controller 的情况下使用 "push"样式从右侧呈现 Controller ?

iOS - 应用商店版本与本地安装版本的行为不同

ios - 将NSDictionary压缩为NSData的有效方法