gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:45:34 27 4
gpt4 key购买 nike

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/

27 4 0