Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法将数据传递到导航栏中嵌入的视图控制器_Ios_Swift_Xcode - Fatal编程技术网

Ios 无法将数据传递到导航栏中嵌入的视图控制器

Ios 无法将数据传递到导航栏中嵌入的视图控制器,ios,swift,xcode,Ios,Swift,Xcode,我正在尝试这样做: 我想将一些数据传递给内嵌在导航栏中的ApplicationViewController,因此出现错误:无法强制转换类型为“UINavigationController”的值 我无法理解如何实现同样的目标。非常感谢你的帮助。谢谢。原因是您无法将数据直接传递到ApplicationViewController,因为InboxViewControllersegue的目标是UINavigationController 因此,首先需要从堆栈访问UINavigationControll

我正在尝试这样做:

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


我无法理解如何实现同样的目标。非常感谢你的帮助。谢谢。

原因是您无法将数据直接传递到
ApplicationViewController
,因为
InboxViewController
segue的目标是
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"
        }
    }
}

原因是您无法将数据直接传递到
ApplicationViewController
,因为
InboxViewController
segue的目标是
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"
        }
    }
}

当传递数据应用程序视图控制器时,该控制器是UINavigationController的rootviewController。您应该给出导航控制器的segue名称,并键入cast as UINavigationController as destination viewcontroller。 获取作为应用程序视图控制器的rootviewController并分配id的值

下面是如何将值分配给应用程序ViewController的代码

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
        if segue.identifier == "navigationSegue" {  // segue of navigationVC
            let navVc = segue.destination as! UINavigationController
            let appVc = navVc.viewControllers.first as! ApplicationsViewController
            appvc.id = "RGB"
        }
    }

当传递数据应用程序视图控制器时,该控制器是UINavigationController的rootviewController。您应该给出导航控制器的segue名称,并键入cast as UINavigationController as destination viewcontroller。 获取作为应用程序视图控制器的rootviewController并分配id的值

下面是如何将值分配给应用程序ViewController的代码

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
        if segue.identifier == "navigationSegue" {  // segue of navigationVC
            let navVc = segue.destination as! UINavigationController
            let appVc = navVc.viewControllers.first as! ApplicationsViewController
            appvc.id = "RGB"
        }
    }

请在屏幕截图中添加有问题的“文本”代码。请在屏幕截图中添加有问题的“文本”代码。