Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to popToRootViewController from within a modal view?

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!

like image 893
Mitch Cohen Avatar asked May 02 '11 06:05

Mitch Cohen


1 Answers

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];
like image 112
tomi Avatar answered Sep 19 '22 00:09

tomi