Reputation: 197
I have an issue with the presentViewController
function.
I have a login menu (A) and a button who display a login form (B). On success login, I present a third view with self.presentViewController
(C).
Login menu (A) -> Login form (B) -> Content (C)
It's work, I can present the third view (C) but the login menu (A) is always visible (I can see it in UI Debug mod).
So, how to close the A ViewController?
Upvotes: 0
Views: 564
Reputation: 4329
If we consider the presentVieController mechanism, this is not a problem or bug. Still if you feel that you don not want your previous controller's remain in Hierarchy, Then you have to change the flow.
Currently your flow is :
A -> RootViewController. B -> LoginScreen C -> Container
I would suggest to refer below answer for best practise.
Best practices for Storyboard login screen, handling clearing of data upon logout
if you give thoughts on handling the flow, you can solve your problem. here are my suggestions
Suggestions :
To dismiss multiple view controller, you can try below code
-(void)dismissModalStack {
UIViewController *vc = self.presentingViewController;
while (vc.presentingViewController) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:NULL];
}
Hope it Helps!
Upvotes: 1
Reputation: 2883
presentViewController
, presents a view controller modally. In other words, over the current view controller’s content, and the current view controller will not get deallocated.
Use the following code for your sample:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: <Identifier as in Storyboard of C>)
(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = vc
If you would like to include a transition, you could replace the last line with something as the following:
UIView.transition(from: currentRootViewController!.view, to: vc.view, duration: 0.8, options: .transitionCrossDissolve, completion: { (_) in
(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = vc
})
Upvotes: 1
Reputation: 31
I think this tutorial has your answer https://www.youtube.com/watch?v=WIaRs2d6Xm0
Upvotes: 0