I have two view controllers A,B in controller scenes. I can create a segue from A -> B. I also create an unwind segue from B -> A with a prepare function. This function is being executed but the value is not being passed to passedDataString is not being passed back.
import UIKit
class homeViewController: UIViewController , UIAlertViewDelegate {
@IBOutlet weak var returnStatusLbl: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
var passedDataString = "QR Return not set"
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
returnStatusLbl.text = passedDataString
}
@IBAction func QRtoHome( _ sender: UIStoryboardSegue) {}
}
import UIKit
class QRViewController: UIViewController {
@IBOutlet weak var wherefromLbl: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destVC = segue.destination as! homeViewController
destVC.passedDataString = "From Done"
}
}
When you return by unwind, viewWillAppear is not called.
You could use an observer: