我开始使用UITabBarController,它很棒。

事情是,我有一些无法从UITabBar访问的视图
(或者以编程方式展示模态,或者我们想在顶部使用一个按钮跳转到它们)

问题是我想保留这些视图中可见的选项卡栏。
根据我的理解,混合使用presentViewControllerUITabBarController是有问题的。

我怎样才能做到这一点?我可以通过编程引用“隐藏的”标签栏元素吗?

只是用一个例子来说明:

视图A,B,C,D在选项卡栏中-通过情节提要-一切都很好。
我需要从顶部导航中单击E和F视图(请不要建议使用滑动式TabBar或多行UITabBar)。
我可以跳到E和F,但是我希望UITabBar仍然可见,以便用户可以从E跳到A。

最佳答案

只需对每个选项卡使用旧的UINavigationController,然后使用[self.navigationController pushViewController:A animated:YES];

这就是设置在代码中的样子:

SGTabBarViewController *rootVC = [[SGTabBarViewController alloc] init];

SGFirstTabViewController *firstVC = [[SGFirstTabViewController alloc] init];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:firstVC];
SGSecondTabViewController *secondVC = [[SGSecondTabViewController alloc] init];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondVC];
SGThirdTabViewController *thirdVC = [[SGThirdTabViewController alloc] init];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:thirdVC];
SGForuthTabViewController *fourhtVC = [[SGForuthTabViewController alloc] init];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:fourhtVC];

rootVC.viewControllers = @[navController1, navController2, navController3, navController4];

self.window.rootViewController = rootVC;
[self.window makeKeyAndVisible];


如果要在每个VC上显示UITabBar,只需在其上使用hidesBottomBarWhenPushed = NO;

但是,没有办法使UITabBar在以模态显示的视图上可见。

关于ios - 导航到UITabBar上没有的ViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23240797/

10-14 20:09
查看更多