unable to use unwind segues with custom view controller containment

Originator:koziarski
Number:rdar://12455238 Date Originated:09-Oct-2012 09:26 AM
Status:Open Resolved:
Product:iPhone SDK Product Version:6
Classification:Serious Bug Reproducible:Always
 
09-Oct-2012 09:26 AM Michael Koziarski:
Summary:

When using custom view controller containment, unwind segues always raise internal consistency exceptions, even when overriding the relevant methods in the documentation.

Steps to Reproduce:

1) Create two view controllers, and connect them up with a custom segue
2) Create an unwind ib action on the parent view controller
3) In the segue implemntation, transition from one view controller to the next using the view controller containment apis:

-(void) perform {
    UIViewController *container = [self sourceViewController];
    UIViewController *child = [self destinationViewController];
    [container addChildViewController:child];
    [container.view addSubview:child.view];
    child.view.center = container.view.center;
    
    [UIView transitionWithView:container.view
                      duration:0.35
                       options:UIViewAnimationOptionCurveEaseInOut
                    animations:^{
                        child.view.alpha = 1;
                    } completion:^(BOOL finished) {
                        [child didMoveToParentViewController:container];
                    }];
}

3) In the parent view controller override viewControllerForUnwindSegueAction:fromViewController:withSender: to ensure it's returning the right value

-(UIViewController *) viewControllerForUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender {
    id default = [super viewControllerForUnwindSegueAction:action fromViewController:fromViewController withSender:sender];
    NSAssert1(default == self, @"Expected the default view controller to be self but was %@", default);
    return default;
}

4) override canPerformUnwindSegueAction:fromViewController:withSender to ensure the parent view controller is selected.

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

5) override segueForUnwindingToViewController:fromViewController:identifier to return an unwind segue

-(UIStoryboardSegue *) segueForUnwindingToViewController:(UIViewController *)toViewController
                                      fromViewController:(UIViewController *)fromViewController
                                              identifier:(NSString *)identifier {
    NSLog(@"calling segueForUnwindingToViewController on the container");
    return [[USCustomUnwindSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController];
}

6) Tap on the button which is bound to the unwind segue

Expected Results:

The unwind segue is executed and the transition takes place back to the parent view controller

Actual Results:

viewControllerForUnwindSegueAction: fromViewController: withSender: is called and the correct controller is returned from it, however the application then terminates with NSInternalInconsistencyException complaining that it can't find a view controller to execute unwinding to.

2012-10-01 10:56:33.627 UnwindSegues[12770:c07] *** Assertion failure in -[UIStoryboardUnwindSegueTemplate _perform:], /SourceCache/UIKit_Sim/UIKit-2372/UIStoryboardUnwindSegueTemplate.m:78
2012-10-01 10:56:33.628 UnwindSegues[12770:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not find a view controller to execute unwinding for <USCustomContainerViewController: 0x75949a0>'
*** First throw call stack:
(0x1c8e012 0x10cbe7e 0x1c8de78 0xb61f35 0x581711 0x45ab54 0x10df705 0x16920 0x168b8 0xd7671 0xd7bcf 0xd6d38 0x4633f 0x46552 0x243aa 0x15cf8 0x1be9df9 0x1be9ad0 0x1c03bf5 0x1c03962 0x1c34bb6 0x1c33f44 0x1c33e1b 0x1be87e3 0x1be8668 0x1365c 0x1e7d 0x1da5)
libc++abi.dylib: terminate called throwing an exception


Regression:

This is not a regression as unwind segues were not previously available, however it makes unwind segues impossible to use with view controller containment.

Notes:

I have a full sample project online: https://github.com/NZKoz/UnwindSegues I will also attach it here for completeness.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!