-segueForUnwindingToViewController: fromViewController: identifier: not being called -segueForUnwindingToViewController: fromViewController: identifier: not being called ios ios

-segueForUnwindingToViewController: fromViewController: identifier: not being called


To add to the answer from @Jeremy, I got unwinding from a modal UIViewController to a UIViewController contained within a UINavigationController to work properly (I.e how I expected it to) using the following within my UINavigationController subclass.

// Pass to the top-most UIViewController on the stack.- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)             toViewController fromViewController:(UIViewController *)             fromViewController identifier:(NSString *)identifier {   UIViewController *controller = self.topViewController;   return [controller segueForUnwindingToViewController:toViewController                                  fromViewController:fromViewController                                          identifier:identifier];}

.. and then implementing the segueForUnwindingToViewController as usual in the actual ViewController inside the UINavigationController.


This method should be declared on the parent controller. So if you're using a Navigation Controller with a custom segue, subclass UINavigationController and define this method on it. If you would rather define it on one of the UINavigationController's child views, you can override canPerformUnwindSegueAction:fromViewController:withSender on the UINavigationController to have it search the children for a handler.

If you're using an embedded view (container view), then define it on the parent view controller.

See the last 10 minutes of WWDC 2012 Session 407 - Adopting Storyboards in Your App to understand why this works!


If you're using a UINavigationController and your segue is calling pushViewController then in order to use a custom unwind segue you'll need to subclass UINavigationController and override - (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier.

Say I have a custom unwind segue called CloseDoorSegue. My UINavigationController subclass implementation might look something like:

- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier {UIStoryboardSegue* theSegue;if ([identifier isEqualToString:@"CloseDoor"]) {    theSegue = [CloseBookSegue segueWithIdentifier:identifier source:fromViewController destination:toViewController performHandler:^(void){}];} else {    theSegue = [super segueForUnwindingToViewController:toViewController fromViewController:fromViewController identifier:identifier];}return theSegue;

}

Set your UINavigationController subclass as the navigation controller class in the storyboard. You should be good to go provided you have setup the Exit event correctly with "CloseDoor" as the identifier. Also be sure to call 'popViewControllerAnimated' in your unwind segue instead of dismiss to keep in line with UINavigationControllers push/pop mechanism.