在支持iOS 12和iOS 13时无法设置根视图控制器

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

我在设置根视图控制器时遇到问题。我在完成教程后更改了根视图控制器,我在应用程序委托类中有一个方法可以更改rootviewcontroller,我使用应用程序委托的共享实例调用该方法。此功能在iOS 12及更低版本的iOS 12上正常运行,但在13版中则可能不是这样,因为在13版中,Scene Delegate包含在Picture中。谁能帮我解决这个问题?

ios swift appdelegate swift5.1 uiscenedelegate
1个回答
0
投票

在您项目的SceneDelegate.swift文件中可用

它将具有委托方法:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)

这里的完整代码:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

if let windowScene = scene as? UIWindowScene {

    self.window = UIWindow(windowScene: windowScene)

    let viewController =
        storyboard.instantiateViewController(withIdentifier: "viewController")
    self.window!.rootViewController = viewController
    self.window!.makeKeyAndVisible()
}
}
© www.soinside.com 2019 - 2024. All rights reserved.