I am trying to pass a text value from one VC (call it the secondVC) to another VC (firstVC). The information in the secondVC will dictate the text value of a textfield in the firstVC. I have tried using documentation to figure this out, but I must be getting extremely confused or something else is up - I can't figure out which.
In my secondVC:
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "saveSegue") {
let destinationVC = segue.destination as! firstVC
destinationVC.addressTextField.text = searchBar.text
}
}
@IBAction func savePressed(_ sender: Any) {
performSegue(withIdentifier: "saveSegue", sender: self)
}
After segueing back to the firstVC, the textField is not filled out with the searchBar text as expected. (The searchBar text is not nil) From my understanding, when the button is selected in the secondVC and calls the performSegue, it will also call upon the prepareForSegue and set the addressTextField.text value while segueing back to the firstVC. I am not certain if my logic is correct.
In Your FirstViewController
@IBAction func dismissSearchVC(_ sender: UIStoryboardSegue) {
let sourceVC = sender.source as! viewController2
addressTextField.text = sourceVC.searchBar.text
}
In your secondViewController
var searchedText = ""
@IBAction func savePressed(_ sender: Any) {
performSegue(withIdentifier: "saveSegue", sender: self)
}
Now connect your viewController to exit on top and add an identifier To that segue as saveSegue and select dismissSearchVC from the drop down
then select your segue from here
Now select "unwind segue to DismissSearchVC" and in attribute inspector add the identifier..