简体   繁体   中英

Swift - passing values via segue

I'm trying to pass few variables via a segue. Initially I capture 6 variables on the first screen which I would like to pass on to the second view controller.

Each variable is captured through a text box capturing an integer and I called them T1, T2, T3 ... T6. At present I refer to the value through T1.text.toInt()!. Before I pass these values via segue, should I first create a variable like var T1 = T1.text.toInt()! ?

What is the best way of designing this?

inside prepareForSegue you have access to the UIController instance that will open:

class FirstPageUIViewController:UIViewController {
...

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    var controller = (segue.destinationViewController as! MyNextViewController)
    controller.T1 = "value to pass"
  }

}

This means you define you variables in MyNextViewController (the controller for your second screen) and the variables are already set when your MyNextViewController instance takes over control.

You also might decide to name your variables starting with small letters according to the swift style guide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM