Unwind Segue的自定义Segue类 [英] Custom Segue Class for Unwind Segue

查看:97
本文介绍了Unwind Segue的自定义Segue类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

我发现为了实现自定义展开segue,我必须继承UINavigationController并重写此方法,如下所示:

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

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

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

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

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

希望这可以帮助某人。

这篇关于Unwind Segue的自定义Segue类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆