Pregunta

I want to make a back button from a modal view to the Main view.

The View Controller is embedded in the navigation controller. The menu button take me to the Second View Controller. There I have a back button who works fine using this:

[self.navigationController popViewControllerAnimated:YES];

I want to go back to the Main View Controller from the Page Two VC.

I have tried:

- (IBAction)goToRootView:(id)sender {

[self.presentingViewController dismissViewControllerAnimated:(NO) completion:nil];
[self.navigationController popViewControllerAnimated:YES];
}

and:

- (IBAction)goToRootView:(id)sender {


[self dismissViewControllerAnimated:(NO) completion:nil];
[self.navigationController popViewControllerAnimated:YES];
}

The first just goes back to the Second VC, the last sends and lldb error.

How can I go from Mantras Page Two VC to Main VC?

Thank you for your help!

¿Fue útil?

Solución

You can tray this...

CHS_View_Controller *oldView = [self.storyboard instantiateViewControllerWithIdentifier:@"CHS_View"];
UINavigationController *yourNavigationController = [[UINavigationController alloc]  initWithRootViewController:oldView];

yourNavigationController.modalTransitionStyle= UIModalTransitionStyleCrossDissolve;

[self presentViewController:yourNavigationController animated:YES completion:nil];

for that you must:

1) import you dest controller

#import "CHS_View_Controller.h" // your controller name

and

2) set an Identifier for your CHS_Controller, "CHS_View" in the bellow example (into the Storyboard Editor and in the Attributes Inspector)

Otros consejos

In the first snippet, instead of

[self.navigationController popViewControllerAnimated:YES];

try

[self.navigationController popToRootViewControllerAnimated:YES];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top