Creating a navigationController programmatically (Swift)

后端 未结 6 369
盖世英雄少女心
盖世英雄少女心 2020-11-29 19:21

I\'ve been trying to redo the work on my app programmatically. (Without the use of storyboards)

I\'m almost done, except making the navigation controller manually.

6条回答
  •  佛祖请我去吃肉
    2020-11-29 19:37

    Value of type 'AppDelegate' has no member 'window'

    For those building newer projects with SceneDelegate.swift, you can use the 'var window: UIWindow?' in SceneDelegate instead of the removed 'var window' in AppDelegate

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = (scene as? UIWindowScene) else { return }
    
        window?.windowScene = windowScene
        window?.makeKeyAndVisible()
    
        let viewController = ViewController()
        let navViewController = UINavigationController(rootViewController: viewController)
        window?.rootViewController = navViewController
    }
    

提交回复
热议问题