1

I have several views. Here's what it looks like: First view is StartViewController (arrow), which opens TabBarController which is owner of two other views - FavoriteViewController and MapViewController. How to close all of them and go back to the StartViewController? This should work like starting the app from first view. I found similar question, but unfortunately it doesn't work. How to go back to the initial ViewController the right way?

enter image description here

beginner992
  • 659
  • 1
  • 9
  • 28
  • *"... StartViewController (arrow), which opens TabBarController ..."* -- first question: what do you mean by "opens"? Do you *present* the TabBarController? If so, you can *dismiss* it. Second question: ***why*** do you want to do that? It sounds like it could really confuse the user, and users don't like having to "figure out" different navigation in every app they use. – DonMag Mar 30 '21 at 19:55
  • I tried dismiss but it works different. Dismiss starts the first ViewController in the navigation stack, not the initial VC. So it gives me a blank view. In the first VC app downloads the data. It's more convenient and takes less code. – beginner992 Mar 30 '21 at 20:04
  • That doesn't make any sense... if `StartViewController` ***presents*** `TabBarController`, `StartViewController` can then ***dismiss*** it. Doesn't matter how deep you are into a navigation controller stack, or which tab you are on. – DonMag Mar 30 '21 at 20:16
  • The word "present" here means something very specific: that you call `present(_:animated:completion:)` to display your view controller modally. Once you are done with a view controller you've displayed that way, you call `dismiss(animated:completion:)` to dismiss that modal. – Duncan C Mar 30 '21 at 20:20

1 Answers1

0

1. First dismiss your current viewController by self.CurrentVC.dismiss(animated: true, completion: nil)

2. then, present/show your first or intial viewController present(firstVC,animated: true,completion: nil)

Here CurrentVC is the name for your current viewController and firstVC will be the name of your first viewController that you want to show.

Saurav_Sharma
  • 130
  • 1
  • 10