Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 6 storyboards: modal view is not dismissing

I am using Xcode 4.5 and iOS 6.

I am building a universal application that is using storyboards. I have one view controller that has a button in the navigation bar. When the button is tapped, I am using a segue to present another view controller as a modal. The modal view controller has a Cancel and a Save button in its navigation bar. In the storyboard, the modal button items are linked to actions on the new Exit action which is supposed to unwind to the parent view controller, dismiss the modal, and call an action handler.

This works fine on the iPhone, but I am seeing problems on the iPad. On the iPad, when the modal is presented in full screen, everything works. When I change the mode to Page Sheet or Form Sheet (which is the desired behavior in my case), the action handler gets called, but the modal view controller is not being dismissed automatically.

Has anyone else seen this behavior? Is there something that you have done to fix it?

Thank you.

like image 506
Michael Collins Avatar asked Oct 27 '12 17:10

Michael Collins


2 Answers

Thanks for asking about this, since I've just encountered the same issue. I assume that it's a bug, but I have not yet filed it with Apple. In the meantime, the easy workaround is to call dismissViewController:animated: in your unwind: implementation (that is, in the action method connected to the unwind segue through the Exit icon), thus dimissing the modal view yourself.

My only worry about this solution is that if this is a bug and Apple eventually fixes it, will their fix break any code using this workaround? Only time will tell...

Later Edit: I have discovered a much nicer workaround. Subclass the parent (container) class of the class you want to unwind to, and implement unwind there instead. For example, in my app, the situation looks like this:

UISplitViewController
    UINavigationController
        MasterViewController
    UINavigationController
        DetailViewController ----> modal segue ----> ThirdViewController

The exit / unwind segue from ThirdViewController back to DetailViewController demonstrates the bug - the unwind: implementation is called, but the form view is not dismissed. But if I subclass UISplitViewController and implement unwind: there, it works fine. (The unwind: implementation can be empty; the point is that the form view is dismissed automatically.) So evidently this is an issue having to do with container view controllers, and you can solve it by letting the container handle it.

See my example project, uploaded to https://github.com/mattneub/Programming-iOS-Book-Examples/tree/master/ch19p561containerViewControllerStoryboard3Bug

like image 188
matt Avatar answered Feb 21 '23 21:02

matt


Cool if the modal view controller were dismissed automatically, but in Apple's example here, they use a modal transition for the segue but then explicitly call dismissViewControllerAnimated:completion: in the unwind (Exit) action to dismiss it.

like image 30
bfalling Avatar answered Feb 21 '23 22:02

bfalling