【问题标题】:Navigation Controller not being displayed when created programmatically以编程方式创建时未显示导航控制器
【发布时间】:2020-02-09 12:57:19
【问题描述】:

我刚刚更新到 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,但我将情节提要作为“初始视图控制器”。即使我清除了项目常规设置中的“主界面”字段,这也完全忽略了我在 appdelegate 中的代码。

我还想指出,我的代码不应该在 appdelegate 中,而是应该在 SceneDelegate 中。更多信息在这里:https://medium.com/@ZkHaider/apples-new-uiscene-api-a-programmatic-approach-52d05e382cf2

【问题讨论】:

  • 您是否尝试为导航栏设置标题?

标签: ios swift xcode uinavigationcontroller ios13


【解决方案1】:

也许你可以尝试使用导航控制器的标识符

    let destination = storyboard.instantiateViewController(withIdentifier: "--navigation controller identifier--") as! --class name--
    navigationController?.pushViewController(destination, animated: true)

【讨论】:

    猜你喜欢
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    • 2011-04-14
    相关资源
    最近更新 更多