首页 > 解决方案 > 无法将数据传递到嵌入在导航栏中的视图控制器

问题描述

我正在尝试这样做: 在此处输入图像描述

我想将一些数据传递给嵌入在导航栏中的 ApplicationsViewController,因此出现错误:无法转换类型“UINavigationController”的值

我无法理解如何实现它。非常感谢您的帮助。谢谢你。

标签: iosswiftxcode

解决方案


原因是您不能将数据直接传递到ApplicationViewControllersegueInboxViewController的目的地是UINavigationController.

因此,首先您需要访问UINavigationController,然后ApplicationsViewController从堆栈中访问。

试试下面的代码:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "goToApplications" {
        if let navigation = segue.destination as? UINavigationController, let applicationVC = navigation.topViewController as? ApplicationsViewController {
            applicationVC.id = "RGB"
        }
    }
}

推荐阅读