title: Show a View Controller that is already on Navigation Stack
body: <p>I have a Tab bar Controller (with a bottom menu) and also a top menu. The problem is that I don't want to link the yellow and green views to the tab bar (because the user is going to change the views using the top menu rather than the bottom menu).  </p>
  
  <p>I'm having a problem that every time I click the buttons a new instance of the view is going to stack (so I end up having something like V1 -> V2 -> V3 -> V2 -> V4 and so on)</p>
  
  <p>My partial solution is to make something like this:</p>
  
  <pre><code>@IBAction func yellowViewButtonAction(_ sender: AnyObject)
  {
      let storyboard = UIStoryboard(name: "Main", bundle: nil)
      let controller = storyboard.instantiateViewController(withIdentifier: "YelloViewController") as! YelloViewController
  
      if let viewControllers = navigationController?.viewControllers {
          for viewController in viewControllers {
              // some process
              if viewController is YelloViewController {
                  print("View is on stack")
              }
          } 
  
           let storyboard = UIStoryboard(name: "Main", bundle: nil)
           let controller = storyboard.instantiateViewController(withIdentifier: "YelloViewController") as! YelloViewController
           self.navigationController?.pushViewController(controller, animated: false)
      }
  }
  </code></pre>
  
  <p>I can see that the view is on navigation stack because the <code>if</code> statement inside the <code>for</code> is <code>true</code>. The question is, how can I retrieve it instead of pushing a new instance of the same view? (Because besides the huge memory problem that this present I also lose any data I had on the view).</p>
  
  <p>I want to keep everything on the stack intact.</p>
  
  <p>Example:</p>
  
  <p>V1 -> V2 -> V3 -> V4 (current view)</p>
  
  <p>If I go back to V1 from V4 I still want to have V4, V3 and V2 on the navigation controller stack.</p>
  
  <p>Another question is that if this solution is something that Apple might refuse.</p>
  
  <p>I appreciate any help.</p>
  
  <p><a href="https://i.stack.imgur.com/FoUiQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FoUiQ.png" alt="enter image description here"></a></p>