Xcode - Passing datas between 2 views by dismissViewControllerAnimated

。_饼干妹妹 提交于 2020-01-17 19:06:57

问题


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.



来源:https://stackoverflow.com/questions/29128386/xcode-passing-datas-between-2-views-by-dismissviewcontrolleranimated

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!