【发布时间】: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 的回答,基本上说我必须自己管理每个视图控制器中的标签栏。我尽量避免这种情况。
仅在导航控制器根目录中正确隐藏和显示标签栏我错过了什么?
【问题讨论】:
-
似乎我在这个答案中找到了一种合理的方法来处理这个问题:stackoverflow.com/a/23269013我现在正在检查它
-
任何有足够权限的人都可以随意投票为:stackoverflow.com/q/5641465我将使用stackoverflow.com/a/23269013的方法
标签: ios objective-c uinavigationcontroller uitabbarcontroller