Unwind Segue的自定义Segue类

可以在“故事板”构建器中单击“标准/前向搜索”,并且可以将样式更改为“自定义”。 此时可以指定Segue类。 然而,这对于Unwind Segue来说是不可能的。 Unwind Segues仅具有要指定的标识符和操作。 它的类型是“Unwind Segue”,但有没有办法为这些Unwind Segues创建自定义Segue类?

我发现为了实现自定义展开segue,我必须inheritanceUINavigationController并覆盖此方法,如下所示:

-(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]; } } 

然后在需要自定义展开segue的UIViewController中覆盖此方法:

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

最后在您的自定义UIStoryboardSegue类中,只需覆盖“ – (void)perform:”方法,并放置您需要的任何动画(或者在我的情况下缺少动画)。

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

希望这有助于某人。

也许你想看看http://dadabeatnik.wordpress.com/2013/10/13/custom-segues/文章。 它非常详细地解释了自定义segue。