Reputation: 483
Let me start by saying that I want to do all of this without storyboards. My situation is as follows: I have a login page for the user. On the login page the user can login, or be taken to a register page. When the user registers successfully, they are taken to the main menu. However, if I they click logout from the main menu, dismissing the main menu viewcontroller takes me back to the register page (which makes sense).
The problem is I need to take the user to the login page. However, I cannot present the original login page because I get the error "Warning: Attempt to present on which is already presenting "
Is there some sort of way for me to dismiss 2 view controllers? Or maybe run a line of a code on a view controller if it is presented from a certain view controller?
Thank you!
This is the solution that I used from the main menu and it worked
if(self.presentingViewController == registerPage){
registerPage.dismissViewControllerAnimated(true, completion: nil)
}
self.dismissViewControllerAnimated(true, completion: nil)
Upvotes: 1
Views: 60
Reputation: 5602
No need to switching to Navigation controllers.
If you are presenting view controller than simply try this:
For Objective-C:
[[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];
For Swift:
self.presentingViewController!.presentingViewController!.dismissViewControllerAnimated(true, completion: {})
Hope it will work for you.
Upvotes: 1
Reputation: 89172
If you are using a navigation controller, you can get the viewControllers
array property, build up a new array without the viewControllers you want to dismiss and set the property with the new array.
Upvotes: 2