如何在这两个视图控制器之间快速传递数据 [英] how to pass data between these two view controllers in swift

查看:27
本文介绍了如何在这两个视图控制器之间快速传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这种情况下,我有标签栏控制器和导航控制器之间两个 VC,这意味着首先我想在第一个 VC 和标签栏控制器之间传递数据,其次我想将相同的数据从标签栏控制器传递给导航控制器,最后传递给最后一个 VC,我在例如网络,但我没有发现任何有用的东西.

in this case i have tabbar controller and navigation controller between the two VC,which means firstly i want to pass data between the first VC and the tabbar controller, and secondly i want to pass the same data from the tab bar controller to navigation controller , and finnally to the last VC,i searched for example in the net but i didn't find anything useful.


请你帮我在这两个视图控制器之间传递数据,任何例子都会很棒,谢谢.

please can u help me pass data between these two viewcontrollers ,any example will be great, thaank's.

推荐答案

为故事板中的 segue 设置标识符(单击 segue,然后在右侧菜单上转到属性检查器),然后您可能需要单击在 didSelectRowAt 中制作 segue 的单元格,在那里执行此操作:

Set an identifier to the segue in your storyboard (click on the segue and then on the right menu go to attributes inspector) and then you probably need to click on the cell to make the segue in didSelectRowAt, do this in there:

self.performSegue(withIdentifier: "YOUR IDENTIFIER", sender: DATA TO PASS or nil)

然后创建segue函数

And then create the segue function

override func prepare(for segue: UIStoryboardSegue, sender: Any!){
    if (segue.identifier == "YOUR IDENTIFIER") // good to have if you have multiple segues
    {
        let secondVC = segue.destination as! SecondViewController
        secondVC.str = "DATA" // now you can access public variables and functions from the second viewController
    }
}

这篇关于如何在这两个视图控制器之间快速传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆