[英]How to set a UITabBarController as rootViewController from Storyboard
Short question:简短的问题:
How can I launch and make a UITabBarController be the rootViewController of my app after starting with a Storyboard?从 Storyboard 开始后,如何启动 UITabBarController 并将其设置为我的应用程序的 rootViewController?
Long question:长问题:
I'm not a swift expert, but I managed to create a complete app using XIBs from the beginning.我不是 swift 专家,但我从一开始就设法使用 XIB 创建了一个完整的应用程序。 Now I need my app to start with a Storyboard as a new requirement to post updates to the appstore from 01/07/2020, but I never used it to build my views.
现在我需要我的应用程序以 Storyboard 作为从 2020 年 1 月 7 日起向应用商店发布更新的新要求,但我从未使用它来构建我的视图。 It was easy to modify my app to have my Storyboard as an entry point, but the problem is that my initial view today is a TabController, and I don't know how to navigate from my initial Storyboard to my TabController.
修改我的应用程序以将我的 Storyboard 作为入口点很容易,但问题是我今天的初始视图是 TabController,我不知道如何从初始 Storyboard 导航到我的 TabController。
My AppDelegate today works something like this:我今天的 AppDelegate 是这样工作的:
var window: UIWindow?
func application(_application: UIApplication, didFinishLauchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
// initiate UINavigationControllers and UITabBarController here...
tabController.viewController = [nav1, nav2, nav3, nav4]
tabController.modalPresentationStyle = .fullScreen
self.window!.rootViewController = tabController
self.window!.makeKeyAndVisible()
}
All my attempts ended with a white screen after showing my Storyboard without showing my TabBar.在显示我的 Storyboard 而不显示我的 TabBar 后,我所有的尝试都以白屏结束。
One of these attempts was this:这些尝试之一是:
override func loadView() {
super.loadView()
// initiate tabController the same way I did in the AppDelegate
UIApplication.shared.keyWindow?.rootViewController = tabController
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.