2

I've got UIViewController that I've loaded from a UIStoryboard by sending it initialViewController (it is not my App's main storyboard).

I have an unwind segue used in that storyboard. Its exit point is in an unwind action of a UIViewController that lives in scene of the main UIStoryboard.

I display this view controller with code, rather than with a segue.

If I present the loaded view controller with presentViewController:animated:completion:, the unwind segue works fine and finds the appropriate handler.

However, the unwind segue does not work if I wrap up my presented view controller in a UIPopoverController, and then present the popover. I can breakpoint the unwind action and it doesn't get called.

In their technical note about how unwind segues work, Apple cover the process of looking up a destination view controller.

How an Unwind Segue Determines its Destination View Controller When an unwind segue is initiated, it must first locate the nearest view controller in the navigation hierarchy which implements the unwind action specified when the unwind segue was created. This view controller becomes the destination of the unwind segue. If no suitable view controller is found, the unwind segue is aborted.

Starting from the view controller that initiated the unwind segue the search order is as follows:

  1. The next view controller in the responder chain is sent a viewControllerForUnwindSegueAction:fromViewController:withSender: message. For a view controller presented modally, this will be the view controller that called presentViewController:animated:completion:. Otherwise, the parentViewController. The default implementation searches the receiver's childViewControllers array for a view controller that wants to handle the unwind action. If none of the receiver's child view controllers want to handle the unwind action, the receiver checks whether it wants to handle the unwind action and returns self if it does. In both cases, the canPerformUnwindSegueAction:fromViewController:withSender: method is used to determine if a given view controller wants to handle the unwind action.

  2. If no view controller is returned from viewControllerForUnwindSegueAction:fromViewController:withSender: in step one, the search repeats from the next view controller in the responder chain.

(Note my emphasis of the second point.)

So, as far as I can see, what I'm doing should, somehow, just work. The unwind segue will bubble up the responder chain, out of the presented view controller, in to the UIPopoverController out in to whatever is presenting that, and on up the chain – eventually finding my unwind handler.

It's not working though. Any ideas why not?

Benjohn
  • 12,147
  • 8
  • 58
  • 110
  • Doing some digging, it seems if I send an action message from the first responder in the presented view controller when using either a modal view, or a popover, **the presenting view controller doesn't get that action** (remember unwind segues **are** working with a modally presented view controller). So I'm not sure that Apple are referring to the responder chain in terms of the usual discovery mechanism. – Benjohn Feb 09 '15 at 17:02

0 Answers0