title: How to reset navigationviewcontroller ios swift
body: <p>I am having app with Slider where I have provided drop down to switch between users. As soon as app user switch to other user I want to reset entire navigation flow and start it from 1st screen.</p>
  
  <p>For e.g</p>
  
  <p><strong>Screen A -> Screen B -> Screen C -> Screen D -> User opens slider and switch users -> Jump to Screen A (Remove other screen from navigation). We can consider gmail app example here, where we can switch between different accounts and gmail app redirect user to primary inbox.</strong></p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>I am using library for Slider menu available on git.</p>
  
  <p><a href="https://github.com/dekatotoro/SlideMenuControllerSwift" rel="nofollow">https://github.com/dekatotoro/SlideMenuControllerSwift</a></p>
  
  <pre><code>    class AppDelegate: UIResponder, UIApplicationDelegate {
  
         var window: UIWindow?
         var navigationController: UINavigationController?
         var storyboard: UIStoryboard?
         var leftViewController: LeftSidePanelViewController?
         // var uuid: String?
  
         func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
             if Utility.getUserStatus() == 0 {
                 storyboard = UIStoryboard(name: "Main", bundle: nil)
                 let mainViewController = storyboard!.instantiateViewControllerWithIdentifier("LoginViewController") as! LoginViewController
  
                 leftViewController = storyboard!.instantiateViewControllerWithIdentifier("LeftSidePanelViewController") as? LeftSidePanelViewController
  
                 navigationController = UINavigationController(rootViewController: mainViewController)
                 UINavigationBar.appearance().tintColor = UIColor.whiteColor()
                 leftViewController!.mainViewController = navigationController
  
  let slideMenuController = ExSlideMenuController(mainViewController:navigationController!, leftMenuViewController: leftViewController!)
                 slideMenuController.automaticallyAdjustsScrollViewInsets = true
                 slideMenuController.delegate = mainViewController
  
  self.window?.backgroundColor = UIColor(red: 236.0, green: 238.0, blue: 241.0, alpha: 1.0)
                 self.window?.rootViewController = slideMenuController
                 self.window?.makeKeyAndVisible()
                 Utility.setUUID(UIDevice.currentDevice().identifierForVendor!.UUIDString)
             } else {
                 storyboard = UIStoryboard(name: "Main", bundle: nil)
                 let mainViewController = storyboard!.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
                 leftViewController = storyboard!.instantiateViewControllerWithIdentifier("LeftSidePanelViewController") as? LeftSidePanelViewController
                 navigationController = UINavigationController(rootViewController: mainViewController)
                 UINavigationBar.appearance().tintColor = UIColor.whiteColor()
                 leftViewController!.mainViewController = navigationController
  
  let slideMenuController = ExSlideMenuController(mainViewController:navigationController!, leftMenuViewController: leftViewController!)
                 slideMenuController.automaticallyAdjustsScrollViewInsets = true
                 slideMenuController.delegate = mainViewController
  
  self.window?.backgroundColor = UIColor(red: 236.0, green: 238.0, blue: 241.0, alpha: 1.0)
                 self.window?.rootViewController = slideMenuController
                 self.window?.makeKeyAndVisible()
             }
             return true
         }
      }
  </code></pre>
  
  <p>I have tried different solutions for this but nothing seems to be working.</p>
  
  <pre><code>var alreadyPushed = false
             //Check if the view was already pushed
             if let viewControllers = self.navigationController?.viewControllers {
                 for viewController in viewControllers {
                     if let viewController = viewController as? HomeViewController {
                         self.navigationController?.popToViewController(viewController, animated: true);
                         print(" Push Your Controller")
                         alreadyPushed = true
                         break
                     }
                 }
             }
  
             if alreadyPushed == false {
                 print("Pushing...")
                 let YourControllerObject = self.storyboard?.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
                 self.navigationController?.presentViewController(YourControllerObject, animated: true, completion: nil)
  // HERE also tried pushViewController but that was also not working..
                 self.navigationController?.dismissViewControllerAnimated(false, completion: nil)
  
             }
  </code></pre>
  
  <p>Solution 2:-</p>
  
  <p>Also tried self.navigationController?.viewController.removeAll() and then push/present the HomeView but that is also not working.</p>
  
  <p>Anyone having any suggestion or tips to solve this.</p>