3
votes

In my root UIViewController I present a UINavigationController. The UINavigationController ultimately pushes another view (let's call it MyViewController). How can I dismiss the entire UINavigationController (and the views it has pushed) from MyViewController?

From MyViewController, I've tried calling [[self.navigationController presentingViewController] dismissViewControllerAnimated:NO completion:nil] but nothing happend. I've also tried first popping all the view controllers off the navigation controller but, still, the navigation controller was not dismissed.

Thanks!

UPDATE:

I've tracked down what's causing this issue but haven't been able to solve it. The UINavigationController described above is a custom subclass of UIImagePickerController (we'll call it CameraController) with source type UIImagePickerControllerSourceTypeCamera. Everything works as expected (using the answer provided below) until I set a custom cameraOverlayView on the CameraController in viewDidLoad. Commenting out the following lines gets things working:

self.showCameraControls = NO;
UIView *overlay = [[[NSBundle mainBundle] loadNibNamed:@"CameraController" owner:self options:nil] objectAtIndex:0];
self.cameraOverlayView = overlay;
1
how do you present the navigation controller? how do you switch from uiview to navigation? modal ? if so [self dismissModalViewControllerAnimated:YES]; should worku.gen
I'm doing [self presentViewController:navigationController animated:NO completion:nil]. The modal stuff is deprecated in iOS6.scttnlsn
"The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller." Did you try calling dismissViewController just on the navigation controller itself? Also, are you sure self.navigationController isn't nil?Dan F
on your navController's first viewController can you NSLog [self presentingViewController] and [self.navigationController presentingViewController] ... do they both return the same object?foundry

1 Answers

8
votes

You can call dismissViewControllerAnimated:NO on your self.navigationController itself.

[self.navigationController dismissViewControllerAnimated:NO completion:nil];