ios - 从 "unwindForSegue()"迁移到 "segueForUnwindingToViewController()"

标签 ios

Apple API 文档指出 segueForUnwindingToViewController() 已弃用,我应该使用 unwindForSegue() 来代替自定义转场。我找到了 this post但他们似乎仍然使用“segueForUnwindingToViewController()”。

我不确定如何正确使用 unwindForSegue() 因为 segueForUnwindingToViewController() 采用了以下参数

  • 到 View Controller
  • 来自 View Controller
  • 标识符

并返回一个“UIStoryBoardSegue”。例如

  override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue? {
    return MyCustomSegue(identifier: identifier!, source: fromViewController, destination: toViewController, performHandler: { () -> Void in } )
  }

如何使用新的 unwindForSegue() 传递我的标识符并创建我的自定义 segue 实例?

最佳答案

好吧,这并不像看起来那么难。我认为设置自定义转场的方法很少。

先决条件:

  1. 您需要创建自定义 segue 类来执行 UIViewController 之间的转换。不要忘记设置父类 - UIStoryboardSegue。 (例如 CustomSegue)
  2. 您需要覆盖容器 View Controller 中的方法 -unwindForSegue:towardsViewController: 您可以从代码填充您的 segue

重要,您不需要在非容器的自定义 View Controller 中覆盖此方法

一种方式,您可以在 Storyboard中选择您的 segue 并将其设置为您的 segue 类(例如,CustomSegue)

Example where to set custom segue class

另一种方式,您可以从该方法创建 segue 并简单地执行它。例如,

- (void)unwindForSegue:(UIStoryboardSegue *)unwindSegue towardsViewController:(UIViewController *)subsequentVC {
        CustomSegue *segue = [[CustomSegue alloc] initWithIdentifier:<#Segue Identifier#> source:unwindSegue.sourceViewController destination:unwindSegue.destinationViewController];
        [segue perform];
}

这两种方法都可以正常工作。希望这对你有帮助。


P. S. 你可以试试这个测试项目(Xcode 7.3)- https://github.com/igorkislyuk/custom-animation-unwind-segue

关于ios - 从 "unwindForSegue()"迁移到 "segueForUnwindingToViewController()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38070364/

相关文章:

ios - 在其他装配中重复使用装配

ios - XCode:从核心数据图中排除抽象实体

iphone - 使用 PJSIP 取消 SIP 注册

ios - 如何使用EGOCache更快地缓存和加载页面

ios - uniqueUnionOfObjects更改数组的顺序

ios - Swift 主从模板问题(iOS 8 beta 3)

ios - EXC_???在执行 executeFetchRequest 时

ios - 在 iOS 9 中邀请 Facebook 好友

ios - 快速按下按钮时如何翻转整个 Tableview?

ios - 计算属性 : different types between get and set