Printing Variable Unwind Segue - Xcode 8.0 Swift 3.0

时间:2016-10-15 16:56:44

标签: ios swift xcode uinavigationbar unwind-segue

I want to print a variable when a bar button item (on the navigation bar) is pressed. When this bar button item is pressed an unwind segue will happen whilst a variable is set and then it will be printed to the console (log at the bottom of Xcode). This is my code:

    @IBAction func doneNavItem(_ sender: AnyObject) {

    textField.text = var variableUnwind

    print(variableUnwind)

}

I know that the unwind segue is being triggered before the variable can be printed from How to do something before unwind segue action? but the solutions on here do not seem to work or I might be reading it wrong.

Thanks

1 个答案:

答案 0 :(得分:0)

Please move your variable setting code to the prepare for segue method.

@IBOutlet weak var testTextField: UITextField!

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

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

    }