Dismiss Modal NavigationController from pushed ViewController inside

11,276

Just add a bar button item and put this line in its action method:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

The presenting view controller will be the controller that presented the modal, not the navigation controller.

Share:
11,276
jhilgert00
Author by

jhilgert00

Just addicted to learning stuff.

Updated on June 07, 2022

Comments

  • jhilgert00
    jhilgert00 almost 2 years

    I have an iPad app and I'm using the storyboard. I'm presenting a modal view, which I wrap in a UINavigationController. It's a modal "Settings" view with it's own navigation.

    I have a delegate setup to dismiss the modal view itself with a Done button in the Settings view which works fine, but I need to be able to dismiss it even after it has pushed another view when the user taps a setting.

    So, basically a "cancel" button on the right side of the Navigation bar in the pushed views. Instead of having to go back to the first "Settings" view to hit the done button.

    I've tried setting up a second delegate for the pushed view without success:

    enter image description here

  • jhilgert00
    jhilgert00 over 11 years
    That sounds perfect, I'll try it when I get home and report back
  • jhilgert00
    jhilgert00 over 11 years
    Worked great! Thank you Kindly :)
  • Kamleshwar
    Kamleshwar almost 8 years
    Great! You saved lots of my time, Thanks!.