title: How to add multiple navigation controllers programatically?
body: <p>My app starts in view A, all the views have a tabbar with 4 buttons
  that let's you jump to A, B, C, D</p>
  
  <p><a href="https://i.stack.imgur.com/czRLa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/czRLa.png" alt="stacks"></a></p>
  
  <p>what I currently have is this scenario:</p>
  
  <blockquote>
    <p>if you navigate to either, A, B, C, D you go back to the stack bottom
    with all ones on top wiped out.</p>
  </blockquote>
  
  <p>but I need it to behave like in this image, for example these navigation happened</p>
  
  <pre><code>1: A&gt;1
  2: B&gt;3&gt;7
  3: C&gt;2&gt;5&gt;6&gt;8&gt;7
  4: D&gt;9&gt;1
  </code></pre>
  
  <p>now when I move from 1 to B, I go back to 7 which is the top of B</p>
  
  <p>Question: I assume I need more than one navigation controller, right? also I put this in <code>didFinishLaunchingWithOptions</code> function in <code>appDelegate</code>, how to do more than one navigation controller programmatically? And what to use between A, B push or load view controller?</p>
  
  <pre><code>    ////////// NC
  
      let storyboard = UIStoryboard(name: "Main", bundle: nil)
  
      let mainView        = storyboard.instantiateViewControllerWithIdentifier("selectLocation") as! selectLocation // 1 Home
      let searchView      = storyboard.instantiateViewControllerWithIdentifier("2") as! Search // 1 Home
      let friendsView     = storyboard.instantiateViewControllerWithIdentifier("3") as! Friends // 1 Home
      let meView          = storyboard.instantiateViewControllerWithIdentifier("4") as! Me // 1 Home
  
      var nav1 = UINavigationController()
      nav1.viewControllers = [mainView]
      nav1.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
  
      var nav2 = UINavigationController()
      nav2.viewControllers = [searchView]
      nav2.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
  
      var nav3 = UINavigationController()
      nav3.viewControllers = [friendsView]
      nav3.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
  
      var nav4 = UINavigationController()
      nav4.viewControllers = [meView]
      nav4.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
  
      UINavigationBar.appearance().barTintColor = UIColor(red: 176.0/255.0, green: 190.0/255.0, blue: 105.0/255.0, alpha: 1.0)
      UINavigationBar.appearance().tintColor = UIColor.whiteColor()
      UINavigationBar.appearance().barStyle = UIBarStyle.BlackTranslucent
  
      self.window!.rootViewController = nav1
      self.window?.makeKeyAndVisible()
  
      ////////// NC
  </code></pre>