Xcode - 通过dismissViewControllerAnimated在2个视图之间传递数据

时间:2015-03-18 17:09:12

标签: ios xcode swift segue

我使用 dimissViewControllerAnimated 将视图从 Spring Insert Variables 返回到 Spring Element 。同时,我的输入数据应该通过 Spring Element 类中的unwindSecondView函数从 Spring Insert Variables 传递回 Sprint Element 。 / p>

但显然数据没有通过,我的数组:力和刚度仍然不包含值。有人可以就此提出建议吗?

代码来自Spring Insert Variables类

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)

   }
}

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

Storyboard of my 2 views

1 个答案:

答案 0 :(得分:1)

dismissViewControllerAnimated实际上并没有使用unwind segue。展开segue与任何其他segue一样,必须使用performSegueWithIdentifier执行。