2

Showing a modal ViewController works fine:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myView];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];    

In my modal view, I have a navigation button to switch back to the mainmenu. Normally a would call [self.navigationController popToViewController:delegate.viewMainmenu animated:YES]; but thats not possible inside the modal view. How can I interact with the "parent" to call him that he calls popToViewController?

Thanks a lot!

Manni
  • 11,108
  • 15
  • 49
  • 67

2 Answers2

4

use property parentViewController in your modal vc and call [self.parentViewController dismissModalViewControllerAnimated: YES];

Max
  • 16,679
  • 4
  • 44
  • 57
  • Thank you! With dismissModalViewController I can close the modal view, but how can I navigate to my mainmenu? – Manni Jan 25 '11 at 16:22
  • Well, if your main menu is the root vc, then just do popToRootViewController. Another option: make your main menu as singleton (cause it's usually only one per app) and access is like [MainMenu sharedMenu]. Then you can do smth like [self.navigationController popToViewController: [MainMenu sharedMenu]] – Max Jan 25 '11 at 16:24
  • "self.navigationController popToViewController" doesn't work in the modal dialog, it only works in the parent. I try – Manni Jan 25 '11 at 16:53
  • of course it doesn't work :) that's because your modal view controller wasn't push into the navigation stack. 1. dismiss modal. 2. call pop in your parent – Max Jan 25 '11 at 16:59
  • or try self.parentViewController.navigationController popToViewController" – Max Jan 25 '11 at 16:59
  • THIS WORKED FOR ME: 1. save the parent-navigationController in the modal view 2. call "[self.parentViewController dismissModalViewControllerAnimated:NO];" in the modal view 3. call "[navParent popToViewController:delegate.viewMainmenu animated:YES];" in the modal view (navParent is the parent-navigationController that I saved in the view) – Manni Jan 25 '11 at 17:57
  • This is no longer valid as of iOS 5.0, check this: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/parentViewController In short, now you have to use presentingViewController – George Penn. Apr 20 '12 at 17:30
0

If you are asking how to dismiss the modal view controller, you'll want the modal view itself to call:

[self dismissModalViewControllerAnimated:YES];
Eric
  • 3,865
  • 4
  • 32
  • 44
  • Thank you! Yes, dismissModalViewController closes the modal view, but I want to pop some views to go to my mainmenu. – Manni Jan 25 '11 at 16:23