我不会像这样使用故事板和设置场景委托
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let vc = A_ViewController()
let window = UIWindow(windowScene: windowScene)
window.rootViewController = vc
window.makeKeyAndVisible()
self.window = window
}
在此代码中,导航控制器未初始化.而且,如果我像这样在A_View Controller中调用导航控制器:
print(self?.navigationController)
It prints "nil". And, Can't navigate to other ViewControllers.
It make sense because I didn't initialized navigation controller.
如果像这样编辑sceneDelegate代码:
let rootNavigationController = UINavigationController(rootViewController: vc)
window.rootViewController = rootNavigationController
And push other VC from A_ViewController, then
Pushed ViewController has it's own navigation controller
我没有初始化推送VC的navigationController
.为什么推VC有navigationController
个?