Passing variables between View Controllers using a segue

后端 未结 2 1391
野性不改
野性不改 2020-12-28 17:41

I use Swift and Xcode 6 and would like to pass a variable from one View Controller to another using a Segue.

I have created a segue called \'MainToTimer\' which is

2条回答
  •  悲&欢浪女
    2020-12-28 17:53

    In the first ViewController place this (for modal segue):

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        let theDestination = (segue.destinationViewController as ViewController2)
        theDestination.Duration2 = Duration
    }
    

    Change ViewController2 to the name of the second ViewController. In ViewController2 create a class variable:

    var Duration2 = (whatever the type - UInt8 I guess for time)
    

    That's it. You will have in the value of Duration2 the value of Duration from the first ViewController.

提交回复
热议问题