【发布时间】:2020-01-16 02:19:12
【问题描述】:
我想在 willConnectTo 中插入一个 func(configureInitialViewController())(这样我就可以在其他 ViewControllers 中调用相同的 func)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
configureInitialViewController()
}
func configureInitialViewController() {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
if 1>0 {
window.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: ViewController1)
} else {
window.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: ViewController2)
}
self.window = window
window.makeKeyAndVisible()
}
}
【问题讨论】:
-
请给我们更多细节,让我们知道问题是什么。你有错误吗?这是什么?
-
在我看来你需要将
scene传递给你的函数
标签: swift xcode11 swift5.1 rootviewcontroller uiscenedelegate