Xcode - Passing datas between 2 views by dismissVi

2019-09-20 00:01发布

问题:

I have used dimissViewControllerAnimated to return the view from Spring Insert Variables back to Spring Element. At the same time, my input datas should be passed from Spring Insert Variables back to Sprint Element by the function unwindSecondView in Spring Element class.

But apparently the datas are not pass, my arrays: force and stiffness still do not contain value. Can anyone advice on this?

Code From Spring Insert Variables class

class springInsertVariables : UIViewController {

var forceVar = [Float] ()
var stiffVar = [Float] ()
@IBOutlet weak var forceEntered: UITextField!
@IBOutlet weak var stiffnessEntered: UITextField!

@IBAction func submit(sender: AnyObject) {

    forceVar.append((forceEntered.text as NSString).floatValue)
    stiffVar.append((stiffnessEntered.text as NSString).floatValue)

    println(forceVar) //This doesn't print on my output
    println(stiffVar) //This doesn't print on my output
    dismissViewControllerAnimated(true, completion: nil)

   }
}

Code From Spring Element Class

 @IBAction func unwindSecondView(segue: UIStoryboardSegue) {

     if let svcspringinsertvariables = segue.sourceViewController as? springInsertVariables {
        self.force = svcspringinsertvariables.forceVar
        self.stiffness = svcspringinsertvariables.stiffVar
        println(force)
        println(stiffness)
    }
}

回答1:

dismissViewControllerAnimated does not actually use the unwind segue. An unwind segue is like any other segue and must be performed using performSegueWithIdentifier.