Skip to content

Instantly share code, notes, and snippets.

@anitaa1990
Created April 28, 2018 11:43
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/931548eb906725f611a97bd55f3ab2fc to your computer and use it in GitHub Desktop.
Save anitaa1990/931548eb906725f611a97bd55f3ab2fc to your computer and use it in GitHub Desktop.
@IBAction func handleLoginAction(_ sender: Any) {
/*
* This example is when we want to pop current view controller & remove it from navigation backstack
* before adding a new 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 the last view controller i.e. ViewControllerB from the stack */
vcArray!.removeLast()
/* 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