Creating a navigationController programmatically (Swift)

后端 未结 6 363
盖世英雄少女心
盖世英雄少女心 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:41

    Here is another take in the SceneDelegate class:

    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)    
                    let navController = UINavigationController()
                    let viewController = ViewController()
    
                    navController.viewControllers = [viewController]            
                    window.rootViewController = navController
                    self.window = window
                    window.makeKeyAndVisible()
            }
    }
    

提交回复
热议问题