2

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!

roymckrank
  • 689
  • 3
  • 12
  • 27

2 Answers2

0

In the first snippet, instead of

[self.navigationController popViewControllerAnimated:YES];

try

[self.navigationController popToRootViewControllerAnimated:YES];
Jeepston
  • 1,361
  • 7
  • 7
0

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)

TonyMkenu
  • 7,597
  • 3
  • 27
  • 49
  • I have tried your snippet but this error comes out: 2013-01-25 12:44:30.010 Chingosound[2476:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported' – roymckrank Jan 25 '13 at 18:55
  • `- (IBAction)goToRootView:(id)sender { chsViewController *oldView = [self.storyboard instantiateViewControllerWithIdentifier:@"chs_view_controller"]; UINavigationController *mantrasPageTwoViewController= [[UINavigationController alloc] initWithRootViewController:oldView]; mantrasPageTwoViewController.modalTransitionStyle= UIModalTransitionStyleCrossDissolve; [self presentViewController:mantrasPageTwoViewController animated:YES completion:nil]; }` – roymckrank Jan 25 '13 at 18:56
  • Don't use for NavigationController a name identical with one of your VierController - can "colide". Use any other name : UINavigationController *navig", "navC", etc - – TonyMkenu Jan 25 '13 at 18:57
  • From my example, You have to modify just first line. The rest... Can use it untouched – TonyMkenu Jan 25 '13 at 19:06
  • It works now, but it returns me to the main menu with the Nav bar enabled (I have it disabled), maybe I should hide it programmatically? – roymckrank Jan 26 '13 at 00:29
  • very easy, you must add next line: [yourNavigationController setNavigationBarHidden:YES]; – TonyMkenu Jan 26 '13 at 04:21