为什么PerformSegue应该使用字符串,以及如何与UIStoryboardSegue一起使用?

时间:2018-11-02 18:16:35

标签: ios swift segue uistoryboardsegue

例如,使用prepare(for segue:..我可以简单地传递segue值:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let nav = segue.destination as? UINavigationController, let manageCaptureVC = nav.topViewController as? ManageCaptureVC {

    }
}

但是现在我想有选择地取消它,如果它被触发了,并且似乎只能用shouldPerformSegue来取消它,因为在prepare(for segue:..中使用return不会停止任何操作。

shouldPerformSegue使用字符串而不是UIStoryboardSegue。我不确定为什么会这样,我想使用UIStoryboardSegue值。

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
    if debug_tutorialAllowCaptureBtnActions == false {
        return false
    }
    //how do I get segue?
    if let nav = segue.destination as? UINavigationController, let manageCaptureVC = nav.topViewController as? ManageCaptureVC {

    }

    return true
}

1 个答案:

答案 0 :(得分:2)

您需要

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
   if identifier == "segueName" {   
      return
    }
 }

获取segue本身是没有意义的。您只需要知道segue标识符。另外,如果您需要做出决定,请替换

if debug_tutorialAllowCaptureBtnActions == false {
    return false
}

return tutorialAllowCaptureBtnActions