I am looking to build an app with two view controllers (VC1 and VC2) that each contain a timer. I would like for my user to be able to switch back and forth between these views and allow each timer to still run.
Currently, I have been successful in unwinding to either VC1 or VC2 (depending on which I set as the initial view controller), though I am having difficulty in successfully unwinding back and forth (i.e. from VC1 to VC2 back to VC1 and etc.)
I figured I might be able to accomplish this by initially segueing from VC1 to VC2 with a normal segue (from a button press), and though it will unwind back to VC1, I cannot get my app to unwind back to VC2 from here.
My two simple timer view controllers
Here is the code (for VC1):
@IBAction func unwindToSecondView(_ sender: UISwipeGestureRecognizer)
{
performSegue(withIdentifier: "unwindToSecond", sender: self)
}
@IBAction func backFromSecondView(segue: UIStoryboardSegue) {
}
And for VC2:
@IBAction func segueToFirstView(_ sender: UISwipeGestureRecognizer)
{
performSegue(withIdentifier: "unwindToFirst", sender: self)
}
@IBAction func backFromFirstView(segue: UIStoryboardSegue) {
}
I am really new to swift, and have found a couple interesting sources on here (How to unwind two view controllers and Swift Timer() will not update label after switching between views) but have not had much success otherwise -- would really appreciate any advice or ideas for different implementations. Thanks!!