0

我想使用目标 c 以编程方式更改导航的根视图控制器。我正在使用故事板。我试图在应用程序内更改它的委托,但没有奏效,引入了一些新的东西,称为场景委托,我相信我可以从那里更改根目录,但我没有找到与此相关的资源。任何人都可以帮忙吗?

4

1 回答 1

0

使用以下代码:

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = MyRootViewController()
            self.window = window
            window.makeKeyAndVisible()
        }
     }

参考:https ://www.andrewcbancroft.com/blog/ios-development/ui-work/accessing-root-view-controller-ios13-scenedelegate/

以及:如何在 Scene Delegate iOS 13 中设置 rootViewController

于 2020-11-18T09:42:29.433 回答