0

enter image description here

I have case that I can't use navigation controller, I want to back from YellowVC to blueVC. if using navigation controller I usually use

self.navigationController?.popToRootViewController(animated: true)

but If I don't use navigation controller I find there is two way to back from blueVC to yellowVC.

  1. using unwind segue
  2. using present modally like the picture below

enter image description here

so what is the best way to back to first view controller? using unwind segue or using present modally segue?

maximiliano
  • 323
  • 4
  • 13
  • see this for help : https://stackoverflow.com/questions/33520899/single-function-to-dismiss-all-open-view-controllers – Anbu.Karthik Oct 09 '18 at 10:00
  • 1
    Use an unwind segue – Paulw11 Oct 09 '18 at 10:04
  • How to moved from blue to yellow view-controller. Are you using present modally for moving from blue to red and then red to yellow? – Ankit Jayaswal Oct 09 '18 at 12:22
  • then start using navigation-controller – you cannot do better _all of the jobs_ what the nav-controller does / offers (you may not be even aware of those jobs what happens behind the scene). – holex Oct 09 '18 at 15:58

2 Answers2

2

Assuming you are presenting all views, better way is to use unwind Segues.

Van
  • 1,033
  • 9
  • 17
0

I Think it will be easy if you use dismiss view controller.

  • you just have to pass any uniq value to the second view controller class when the back button of third VC class.(any string or any integer)
  • and just check the value with a if condition in the view did load of second VC class then if its matches dismiss the current VC(second VC) thats enough.

3VC class

@IBAction func back_clicked(_ sender: Any) {
dismiss(animated: false, completion: nil)
    2_vcObject.String = "skip2" 
    }

2Vc Class

view did load()

 if string == "skip2"
{
dismiss(animated: false, completion: nil) 
}
Sooraj_snr
  • 16
  • 2