Reputation: 61019
I have this case
LoginViewController - initial ViewController
) present NavigationControllerB
(in NavigationControllerB I have many ViewController) NavigationControllerB
present ViewControllerC
ViewControllerC
present ViewControllerD
In the ViewControllerD
, when the login section is expired, I will move back to LoginViewController
so I want to dismiss all ViewControlelr instead of LoginViewController
?
Any idea to do that? Any help or suggestion would be great appreciated
I have tried like that: When I dismiss the ViewControllerD
successful, I send a block to ViewControllerC
then I continue dismiss the ViewControllerC
.
After that I will dismiss the NavigationControllerB
, but NavigationControllerB
have many ViewController
so I need to write many block code
so I don't think it's a good idea
Upvotes: 0
Views: 88
Reputation: 27448
You can do something like,
[[[[[self parentViewController]parentViewController] parentViewController]parentViewController] dismissViewControllerAnimated:YES completion:^{
// perform task after completion
}];
Make sure that number of parent viewcontroller. this is example dissmiss paraentview controller according to your scenario.
Update :
try something like this,
[self dismissViewControllerAnimated:YES completion:^{
[[[[[self parentViewController]parentViewController] parentViewController]parentViewController] dismissViewControllerAnimated:YES completion:^{
// perform task after completion
}];
}];
Update 2 :
[[[[[self parentViewController]parentViewController] parentViewController]parentViewController] dismissViewControllerAnimated:YES completion:^{
[self dismissViewControllerAnimated:YES completion:nil];
}];
can do something like this, dismiss all parent vc and then dismiss current vc Hope this will help :)
Upvotes: 1
Reputation: 4855
If LoginViewController is your initialViewController, you can use this code :
//dismiss all presented view controllers if any
UIViewController *vc = self.presentingViewController;
while (vc.presentingViewController) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:NULL];
Upvotes: 2