Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

ios - how to pass data between these two view controllers in swift

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.


pass data

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

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
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...