在第二视图控制器中解除Segue错误

时间:2016-12-01 15:23:54

标签: ios swift xcode segue unwind-segue

我试图弄清楚如何实现自定义segue,以便用户可以在本教程(http://www.appcoda.com/custom-segue-animations/)的帮助下向上滑动屏幕以访问下面的故事板。它工作没有问题,直到需要实现倒带segue部分的部分,并且我不断遇到这段代码的错误:

override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue {
if let id = identifier{
    if id == "idFirstSegueUnwind" {
        let unwindSegue = FirstCustomSegueUnwind(identifier: id, source: fromViewController, destination: toViewController, performHandler: { () -> Void in

        })
        return unwindSegue
    }        
}

return super.segueForUnwindingToViewController(toViewController, fromViewController: fromViewController, identifier: identifier)

}

特别是这一行:

return super.segueForUnwindingToViewController(toViewController, fromViewController: fromViewController, identifier: identifier)

它出现如下错误:可选类型'UIStoryboardSegue?'的值没有打开;你的意思是用'!'或'?'?

我尝试用这行代码替换它,认为参数可能存在问题:

return super.segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) 

但是这次我在调用错误中得到参数“fromViewController”的缺少参数。

对于如何解决此问题有任何建议?

1 个答案:

答案 0 :(得分:0)

你必须用“!”打开可选类型UIStoryboardSegue。 :

return super.segueForUnwindingToViewController(toViewController, fromViewController: fromViewController, identifier: identifier)!