Skip to content

Instantly share code, notes, and snippets.

@anitaa1990
Last active April 28, 2018 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anitaa1990/77eb05ea2da376158a7d14c3c1c6b535 to your computer and use it in GitHub Desktop.
Save anitaa1990/77eb05ea2da376158a7d14c3c1c6b535 to your computer and use it in GitHub Desktop.
@IBAction func handleLoginAction(_ sender: Any) {
/*
* This example is when we want to pop all view controllers from navigation backstack
* & add a new view controller as the root view controller to the stack
*/
/* Step 1: Instantiate the new View controller. In this case: ViewControllerC */
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let viewControllerC = storyBoard.instantiateViewControllerWithIdentifier("ViewControllerC") as! ViewControllerC
/* Step 2: Get the list of view controllers from the navigationController */
var vcArray = self.navigationController?.viewControllers
/* Step 3: Remove all the view controllers from the stack i.e. ViewControllerA & ViewControllerB */
vcArray!.removeAll()
/* Step 4: Append the new view controller to the navigation stack */
vcArray!.append(viewControllerC)
/* Step 5: Set the stack of view controllers to the navigationController */
self.navigationController?.setViewControllers(vcArray!, animated: true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment