我刚刚更新到 iOS 13/Xcode 11,我正在尝试将 UIViewController 嵌入到 UINavigationController 中,就像我过去所做的那样。 ViewController 已显示,但我的 NavigationController 未显示。下面是我在 AppDelegate 内的 didFinishLaunchingWithOptions 方法中的内容。
window = UIWindow()
let vc = ViewController()
let navController : UINavigationController = UINavigationController(rootViewController: vc)
navController.navigationBar.titleTextAttributes = [.foregroundColor : UIColor.black]
window?.rootViewController = navController
window?.makeKeyAndVisible()
编辑: 我发现我的错误,我试图以编程方式创建 VC,但我将 Storyboard作为“初始 View Controller ”。即使我清除了项目的常规设置中的“主界面”字段,这也完全忽略了我在 appdelegate 中的代码。
我还想指出,我的代码不应该位于 appdelegate 中,而应该位于 SceneDelegate 中。更多信息请参见:https://medium.com/@ZkHaider/apples-new-uiscene-api-a-programmatic-approach-52d05e382cf2
最佳答案
也许你可以尝试使用导航 Controller 的标识符
let destination = storyboard.instantiateViewController(withIdentifier: "--navigation controller identifier--") as! --class name--
navigationController?.pushViewController(destination, animated: true)
关于ios - 以编程方式创建时不显示导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58350712/