Learn Courses My Dashboard

How do you segue to a specific vc instead of the rootvc?

Hi community,

I can’t find a good tutorial for what I believe is called “unwind segue”.

I have three view controllers: vc1, vc2, vc3

In vc3, I have a save button. When I click it, it goes back to vc1.

How do I make it segue back to vc2 when clicking the save button?

Thanks in advance :))

Instead of segue-ing back, you can just dismiss vc3

(If they are all presented modally) otherwise if they are all in the same navigation stack, you pop the VC

An unwind segue does what you’re mentioning, going back to the rootVC rather than backwards “once” to whatever was there previously. Which I don’t think is what you want

Oh right that makes sense! Thanks Mikaela :))

I was confused cous I found that by definition, it said " An unwind segue lets you jump to any view controller" so I assumed it was a method used to present any given vc.

Anyways, I have added this:

navigationController?.popViewController(animated: true)

dismiss(animated: true, completion: nil)

It does show vc2, but only for a split second. It then goes back to vc1. Hopefully I can figure out why it’s doing so >.<

You don’t do both, only do one or the other

It depends on how you are navigating to each VC

I tried using each of them and it’s still showing me the same result, so I think the problem must be elsewhere

@km0412

If I can chime in here, the important thing to know, as Mikaela is alluding to, is the order in which you are navigating to each VC.

Are you going from vc1 → vc2 → vc3 then back to vc2
or
vc1 → vc3 and then back to vc2
or
vc1 → vc2 → vc3 and then back to vc1?

Let’s assume that your root vc is vc1. Is vc1 embedded in a NavigationController?

Probably what would help is a screenshot of your storyboard.

Hi Chris,

Yes, I’m trying to go from vc1 → vc2 → vc3 then back to vc2.

vc1 is embedded in a NavigationController.

Here are some ss of the storyboard



So the problem is, it shows the “Schedule Recording” vc for a second and goes back to “MozzWear” so I can’t see the list of schedules I make

@km0412

Sorry I’ve taken a while to get back to you.

It’s a bit difficult to make any suggestions to help you out without seeing your code that you have set up for each ViewController.

You say that when you dismiss vc3 (where it looks like you are creating a new entry for Schedule Recording) to go back to vc2 where you have a lists of Recordings, it shows vc2 for a split second and then pops back to vc1 (MozzWear).

I would imagine that in your vc3 you have code to save the new entry so when you go back to vc2 you would have code to reload the tableView in order to see the changes.

If you were prepared to share your code I could take a look for you. If that sounds like a way forward then can you compress your code at the top level folder of the project and create a zip file.

That is really easy to do. Select the top level of your project (the root folder) and then right click on that folder and select Compress “ProjectName”. Upload the zip file to either DropBox or Google Drive and in either of those, create a share link and post here in a reply. If you prefer, you can private message me and post the share link there if you don’t wish to have your code public.

Hi Chris!

Thank you so much for getting back to me. It is much appreciated.

Unfortunately, I had to re-design my project simply because there were changes in needs hence I couldn’t look into this further. I’m so sorry about that :((

@km0412

No problem. All the best

1 Like