Custom Segue class to unwind Segue

In the storyboard builder, you can click Standard / Forward Segue, and the style can be changed to Custom. At this point, you can specify the Segue class. However, this is not possible for Unwind Segue. In Unwind Segues, only the identifier and action are specified. This explains that their type is "Unwind Segue", but is there a way to create a custom Segue class for these Unwind Segues?

+4
source share
2 answers

I found that in order to implement a custom unwind mode, I had to subclass the UINavigationController and override this method as follows:

-(UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier {
UIViewController *controller = self.topViewController;
UIStoryboardSegue *unwindSegue;

if ([controller isKindOfClass:[YourClassThatNeedsCustomUnwind class]]) {
    unwindSegue = [controller segueForUnwindingToViewController:toViewController fromViewController:fromViewController identifier:identifier];
}

if (unwindSegue) {
    return unwindSegue;
} else {
    return [super segueForUnwindingToViewController:toViewController fromViewController:fromViewController identifier:identifier];
}
}

UIViewController, segue, :

 - (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier {
YourCustomUnwindSegue *segue = [[YourCustomUnwindSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController];
return segue;
 }

, UIStoryboardSegue "- (void) :" ( ) ".

- (void)perform
{
UINavigationController *containerVC = (UINavigationController*)[self.destinationViewController parentViewController];
[containerVC popToViewController:self.destinationViewController animated:NO];
}

, -.

+2

All Articles