7

I have a simple UINavigationController which pushes a UIViewController onto the stack via a custom segue. I then implemented an IBAction on the first UIViewController to perform an unwind action and I implement segueForUnwindingToViewController. Unfortunately, the segueForUnwindingToViewController is not being called (I did confirm that canPerformUnwindSegue is being called on the first VC).

I have not seen any simple examples of this behavior. Can anyone please help? Thanks.

Here's the code from the root view controller of the NavigationController.

- (IBAction) unwindFromSegue:(UIStoryboardSegue *)segue {
// unwinds back to here
//[self performSegueWithIdentifier:@"UnwindToObjectManageSegue" sender:self];

}

- (BOOL)canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController
                     withSender:(id)sender {
return YES;
}

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
return YES;
}

- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController
                                  fromViewController:(UIViewController *)fromViewController
                                          identifier:(NSString *)identifier {
ObjectManageObjectDetailSegue *segue = [[ObjectManageObjectDetailSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController];
[segue setUnwinding:YES];
return segue;
}
Clay
  • 635
  • 6
  • 19
  • I assume that you followed the steps from [this answer](http://stackoverflow.com/a/12843906/335858) but things did not work for you, correct? – Sergey Kalinichenko Apr 18 '13 at 20:17
  • That's correct. I followed that to a T. Unfortunately, my unwind segue is not being called. The identifier is being sent correctly, but it the segue itself is never invoked. – Clay Apr 18 '13 at 21:08
  • It would be great if someone could maybe post a sample project which exemplifies what was posted in that thread. I think it's a great example, but it's rather spread out. – Clay Apr 18 '13 at 21:15
  • Where are you trying to unwind to? You say you're unwinding from the first view controller. Do you mean the root view controller of the navigation controller? – rdelmar Apr 19 '13 at 00:18
  • Please post your code for the unwind method. – iOSGuru248 Apr 19 '13 at 13:40
  • I am trying to unwind to the root view controller of the Navigation Controller, yes. – Clay Apr 19 '13 at 18:25

1 Answers1

23

I had the same problem and I finally found a solution: https://github.com/simonmaddox/CustomUnwindSegue

He also had a problem with it not being called. Turns out that any view controller that is in a UINavigationController will not call the presenting view controller but the UINavigationController instead. This means you must subclass that UINavigationController and add that method there instead.

matrinox
  • 472
  • 5
  • 8
  • 4
    OMG, I'd been struggling with this for about a day. Thank you! This really seems like a bit of an oversight in the way storyboards and custom segues work. But at least I have something that works now! – Danny Sung Jul 19 '13 at 21:26
  • Thanks Greeso. Probably person forgot. Also, glad to help Danny Sung – matrinox Jan 14 '15 at 06:31
  • Thanks ! you sure saved me some time. – OthmanT Jan 22 '16 at 06:48