2

I've looked everywhere for this, so as a last resort I figured I should ask the question.

I'm using Storyboard in XCode and have a navigation controller as my initial view. The root view of this navigation controller is a table view. In this table view, I have a button in the navigation bar that flips the view horizontally via a modal segue to a navigation controller. The root view of this controller is my map view. Now, when I want to dismiss this map view using [self dismissViewControllerAnimated:YES completion:nil] it doesn't work. It does if I take out the navigation controller. So, I'm guessing the dismissViewController is getting passed to the navigation controller, and not doing anything. I know I could implement a class for the navigation controller to handle the call and pass it on, but I don't want to do that unless absolutely necessary.

So to solve this question:

  1. I need a way to switch between table view to map view using the flip horizontally animation and vice versa.

  2. I need to have a navigation controller in both views, I could either be the same one, or a different one. I can't seem to find a way to use the same one, since any transitions would be pushes which don't do the flip horizontally transition.

Thanks in advance for the help!

rickster
  • 124,678
  • 26
  • 272
  • 326
WiseOlMan
  • 926
  • 2
  • 11
  • 26
  • Do you mean `dismissModalViewController` instead of `dismissViewController`? – jonkroll Sep 04 '12 at 03:30
  • I'm making my app iOS 6 compatible, dismissModalViewController is deprecated. – WiseOlMan Sep 04 '12 at 05:31
  • Hi, when you model segue to a navigation controller, how did you have the reference of the original controller in a view controller in a new view controller in the new navigation controller? Because when I do prepareforsegue, and segue.destinationViewController it returns navigation controller and not view controller – coolcool1994 May 05 '14 at 06:26

1 Answers1

3

Who is self when you call [self dismissViewControllerAnimated:YES completion:nil]?

The receiver of this message needs to be the view controller which presented the modal view controller you want to dismiss. If you call it on the presented view controller, or (in the case of container view controllers like UINavigationController, one of the view controllers it manages), UIKit will try to do the right thing but won't always succeed.

Presuming the self you refer to is the view controller containing the map view, you can get the presentingViewController property to get the object you should call dismissViewControllerAnimated:completion: on. (And if you need to get the navigation controller that's in between, use the navigationController property.)

rickster
  • 124,678
  • 26
  • 272
  • 326
  • Thank you for pointing out those properties, but unfortunately it's still not working. This is what I tried. From the button on map view, I changed the code to `[[[self navigationController] presentingViewController] dismissViewControllerAnimated:YES completion:nil]` and that didn't work. I also tried `[[self navigationController] dismissViewControllerAnimated:YES completion:nil]` which also didn't work. Any suggestions? – WiseOlMan Sep 04 '12 at 18:23
  • Sorry for the confusion, apparently my function wasn't getting called when the button was pressed, even though it was working earlier -_- To clear up, all three options work `[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]` or `[[self navigationController] dismissViewControllerAnimated:YES completion:nil]` or the easiest one `[self dismissViewControllerAnimated:YES completion:nil]` still goes through the navigation controller to dismiss the modal view appropriately. Thanks for the help, I learned a few more tricks :D – WiseOlMan Sep 04 '12 at 19:04