Last active
April 28, 2018 11:50
-
-
Save anitaa1990/77eb05ea2da376158a7d14c3c1c6b535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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