【发布时间】:2019-04-17 18:26:31
【问题描述】:
我正在以编程方式编写一个带有标签栏和导航控制器的应用程序,我删除了情节提要,当“secondViewController”不属于 mainNavigationController.viewControllers 数组时,该应用程序也可以正常运行并显示导航栏,但是,当我添加 secondViewController 时,导航栏不会显示在视图上。我做错了什么没有显示导航栏?我应该将 mainNavigationController 改为 rootViewController 吗?
let mainNavigationController = MainNavigationController()
let mainTabBarController = MainTabBarController()
let mainViewController = MainViewController()
let secondViewController = SecondViewController()
mainNavigationController.title = "Single Meal"
secondViewController.title = "Group Meal"
mainViewController.title = "Single Meal"
mainNavigationController.viewControllers = [mainViewController, secondViewController]
mainTabBarController.viewControllers = [mainNavigationController, secondViewController]
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = mainTabBarController
【问题讨论】:
-
有点不清楚...使用您显示的代码,您从 2 个选项卡开始 - 选项卡 1 显示一个导航控制器(带导航栏),从
mainViewController开始,您可以推送- to and pop-fromsecondViewController... 和 tab 2 只显示secondViewController当然,not 显示导航栏。这不是你得到的吗? -
以编程方式创建
UINavigationController并在两个视图控制器之间推送/弹出非常简单。为什么不从那里开始,然后添加您的UITabBarController?这样,您至少可以缩小您面临的具体问题的范围。 (它也会向我们澄清一些事情。)
标签: ios swift xcode uinavigationcontroller