【问题标题】:segueForUnwindingToViewController in iOS 9iOS 9 中的 segueForUnwindingToViewController
【发布时间】:2016-04-10 04:05:10
【问题描述】:

我有一个展示视图控制器的自定义 Segue,然后有一个相应的自定义展开 Segue。此代码在 iOS 8 中运行良好,通过生成 UIStoryboardSegue 的子类并实现 perform 方法来实现。然后我在自定义导航控制器中覆盖以下方法

func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String) -> UIStoryboardSegue {
    var segue: UIStoryboardSegue
    if (fromViewController is MyViewController.self) {
        segue = CustomSegue(identifier: identifier, source: fromViewController, destination: toViewController)
        //Custom Unwind Segue
    }
    else {
        var unwindSegue: UIStoryboardSegue = super.segueForUnwindingToViewController(toViewController, fromViewController: fromViewController, identifier: identifier)
        //Normal Unwind Segue
        segue = unwindSegue
    }
    return segue
}

在 iOS 9 中,segueForUnwindingToViewController 已弃用。它仍然适用于 MyViewController CustomSegue;但是,默认展开转场不再适用于任何其他展开转场。尽管在 super 上调用该方法会返回一个 unwind segue,但 segue 永远不会发生,视图控制器永远不会弹出,并且用户永远无法返回到上一个屏幕。所以要明确一点,如果我使用常规的 show segue,则相应的 unwind segue 会调用已弃用的方法,该方法会调用 super 上的方法,并且不起作用。

【问题讨论】:

    标签: swift ios9 unwind-segue


    【解决方案1】:

    如果控制器 B 展开到控制器 A,那么在控制器 A 中:

      @IBAction func viewController-B-DidExit(segue: UIStoryboardSegue) {
    
            let controller = segue.sourceViewController as! viewController-B
    
      }
    

    然后在 viewContoller B 中将要退出的对象连接到出口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-14
      • 2015-12-08
      • 1970-01-01
      • 2017-07-10
      • 2015-12-14
      • 2015-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多