How to popToRootViewController from modal view?

I have a typical set of UITableViewController views. All views have a button that displays the model view. There is a button on this settings screen. I would like this button to reject the modal view and implement popToRootViewController in the UITableViewController navigationController.

Dismissing a modal look is easy:

[self dismissModalViewControllerAnimated:NO];

and it works great. I tried this to open the main UITableViewController:

[self.parentViewController.navigationController popToRootViewControllerAnimated:NO];

and nothing happens.

I can possibly implement a delegate for this to happen, but there are quite a few view controllers with the same settings button (with even more), so the preference will be to find a solution that does not require additional code in each view controller.

Many thanks!

+5
source share
5 answers

Could not find such a solution, so I implemented a protocol / delegate that works fine. Simply:

[self.navigationController popToRootViewControllerAnimated:NO];

in the delegate call.

+1
source

check rdelmal's answer ( fooobar.com/questions/487710 / ... ), it worked like a charm for me. I use this code in action in a modal representation.

[(UINavigationController *)self.presentingViewController  popToRootViewController:NO];
[self dismissViewControllerAnimated:YES completion:nil];
+6
source

Try

[[[[UIApplication sharedApplication].keyWindow] rootViewController] popToRootViewController:YES];
+1

appdelegate

-(void)GotoRoot{
[self.navigationController popToRootViewControllerAnimated:YES];}

[self dismissModalViewControllerAnimated:NO];
[(TestAppDelegate *)[[UIApplication sharedApplication] delegate]) GotoRoot];

, ;

+1

[[self parentViewController] popToRootViewControllerAnimated:NO]
0

All Articles