Reputation: 1645
I have a typical UITableViewController set of views. On all views is a button, which brings up a model view. On that Settings view is a button. I would like that button to dismiss the modal view and implement popToRootViewController on the UITableViewController's navigationController.
Dismissing the modal view is easy:
[self dismissModalViewControllerAnimated:NO];
and that works fine. I've tried this to pop the main UITableViewController:
[self.parentViewController.navigationController popToRootViewControllerAnimated:NO];
and nothing happens.
I can probably implement a delegate to make this happen but there are quite a few view controllers with the same Settings button (with more to come) so a preference to find a solution that doesn't require additional code in each view controller.
Many thanks!
Upvotes: 5
Views: 5281
Reputation: 5201
add a method in your appdelegate file
-(void)GotoRoot{
[self.navigationController popToRootViewControllerAnimated:YES];}
Now call it in your classs on ur logout button
[self dismissModalViewControllerAnimated:NO];
[(TestAppDelegate *)[[UIApplication sharedApplication] delegate]) GotoRoot];
please revert its result;
Upvotes: 1
Reputation: 96
check out the answer by rdelmal (https://stackoverflow.com/a/16311935/1395563), this worked like a charm for me. I use this code in an action in the modal view.
[(UINavigationController *)self.presentingViewController popToRootViewController:NO];
[self dismissViewControllerAnimated:YES completion:nil];
Upvotes: 7
Reputation: 1484
This works for me
[[self parentViewController] popToRootViewControllerAnimated:NO]
Upvotes: 0
Reputation: 1645
Couldn't find a solution like this, so I've implemented a protocol/delegate which works fine. Just:
[self.navigationController popToRootViewControllerAnimated:NO];
in the delegate call.
Upvotes: 1
Reputation: 22587
Try
[[[[UIApplication sharedApplication].keyWindow] rootViewController] popToRootViewController:YES];
Upvotes: 1