iOS 13: Swift - 'Set application root view controller programmatically' does not work

后端 未结 14 1105
北恋
北恋 2020-12-01 01:43

I have following code in my AppDelegate.swift to setup root view controller for an iOS application. But it does not work. It follows Target structure (defined under General

14条回答
  •  囚心锁ツ
    2020-12-01 02:35

    If you don't want to use main storyboard, if you want to create you own views programmatically.

    For xcode 11.

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

        guard let windowScene = (scene as? UIWindowScene) else { return }
        window = UIWindow(windowScene: windowScene)
        window?.makeKeyAndVisible()
        window?.rootViewController = UINavigationController(rootViewController:      ViewController())
    }
    

    This will defenetily work. Thanks

提交回复
热议问题