A Standard / Forward Segue can be clicked on in the Storyboard builder and the style can be changed to Custom. At this point a Segue Class can be specified. However, this is not possible for an Unwind Segue. Unwind Segues only have Identifier and Action to specify. It reasons that their type is "Unwind Segue" but is there a way to create a custom Segue class for these Unwind Segues?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I found that in order to implement a custom unwind segue 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];
}
}
Then in the UIViewController where the custom unwind segue is needed override this method:
- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier {
YourCustomUnwindSegue *segue = [[YourCustomUnwindSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController];
return segue;
}
Lastly in your custom UIStoryboardSegue class just override the "-(void)perform:" method and put whatever animations (or in my case lack of animations) you need.
- (void)perform
{
UINavigationController *containerVC = (UINavigationController*)[self.destinationViewController parentViewController];
[containerVC popToViewController:self.destinationViewController animated:NO];
}
Hope this helps someone out.
回答2:
Maybe you want to have a look at http://dadabeatnik.wordpress.com/2013/10/13/custom-segues/ article. It explains custom segues in great detail.