打印变量 Unwind Segue - Xcode 8.0 Swift 3.0

Printing Variable Unwind Segue - Xcode 8.0 Swift 3.0

我想在按下栏按钮项(在导航栏上)时打印一个变量。当按下此栏按钮项时,将在设置变量时发生展开转场,然后将其打印到控制台(记录在 Xcode 的底部)。这是我的代码:

    @IBAction func doneNavItem(_ sender: AnyObject) {

    textField.text = var variableUnwind

    print(variableUnwind)

}

我知道在可以从 打印变量之前触发了 unwind segue,但是这里的解决方案似乎不起作用或者我可能读错了。

谢谢

请将您的变量设置代码移动到 prepare for segue 方法中。

@IBOutlet weak var testTextField: UITextField!

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        var variableUnwind = ("Whosebug")

        print(variableUnwind)
        let textContents = testTextField.text
        print(textContents)

    }