我的问题是,如何使以下自定义反向转场在iOS 9之前的设备以及运行iOS 9的设备上正常工作?
我有一个自定义转场显示一个视图控制器,然后有一个相应的自定义反向转场。这段代码在iOS 8中运行良好,并通过创建UIStoryboardSegue的子类并实现
在iOS 9中,
我观看了关于storyboards的WWDC演讲,并且能够通过以下方式解决这个问题:a)不再覆盖自定义导航控制器中的此方法,b)进入storyboard,单击自定义segue,并输入
我有一个自定义转场显示一个视图控制器,然后有一个相应的自定义反向转场。这段代码在iOS 8中运行良好,并通过创建UIStoryboardSegue的子类并实现
perform
方法来实现。然后我在我的自定义导航控制器中重写了以下方法:- (UIStoryboardSegue *) segueForUnwindingToViewController: (UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier
{
UIStoryboardSegue *segue;
if([fromViewController isKindOfClass:[MyViewController class]]){
segue = [[CustomSegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController]; //Custom Unwind Segue
}
else{
UIStoryboardSegue *unwindSegue = [super segueForUnwindingToViewController:toViewController fromViewController:fromViewController identifier:identifier]; //Normal Unwind Segue
segue = unwindSegue;
}
return segue;
}
在iOS 9中,
segueForUnwindingToViewController
被弃用。对于MyViewController CustomSegue它仍然有效; 然而,默认的返回动作不再适用于任何其他返回动作。虽然在super上调用该方法会返回一个返回动作,但是该返回动作永远不会发生,视图控制器也不会弹出,用户无法返回到前一个屏幕。所以为了明确,如果我使用常规的show segue,相应的返回动作将调用弃用的方法,该方法将调用super上的方法,并且不起作用。我观看了关于storyboards的WWDC演讲,并且能够通过以下方式解决这个问题:a)不再覆盖自定义导航控制器中的此方法,b)进入storyboard,单击自定义segue,并输入
CustomSegue
作为segue类。不幸的是,由于我针对的是iOS 7,因此我收到警告“只有在iOS 9之前支持类名的自定义segues”,并且自定义返回操作现在无法在iOS 7或iOS 8上工作!