如何在swift5中从appdelegate或scenedelegate提供视图控制器?

问题描述 投票:0回答:1

如何在swift5中从appdelegate或scenedelegate提供视图控制器?我试过了但是没用:

self.window = UIWindow(frame: UIScreen.main.bounds)
                let storyboard = UIStoryboard(name: "Main", bundle: nil)
                let initialViewController = storyboard.instantiateViewController(withIdentifier: "profile")
                self.window?.rootViewController = initialViewController
                self.window?.makeKeyAndVisible()
swift viewcontroller
1个回答
0
投票

问题是您正在将窗口的根视图控制器初始化为实例化的故事板视图。您需要像这样设置窗口的根视图:

    self.window?.rootViewController = ProfileViewController()

这直接将其设置为swift文件,该文件应为某种UIViewController,并且不使用情节提要。

© www.soinside.com 2019 - 2024. All rights reserved.