Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does shouldPerformSegue use a string, and how do I use a UIStoryboardSegue with it instead?

For instance, with prepare(for segue:.. I could simply pass the segue value:

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

    }
}

But now I want to optionally cancel it if it's triggered, and it only seems I can do that with shouldPerformSegue, since using return in prepare(for segue:.. does not stop anything.

shouldPerformSegue uses a String instead of UIStoryboardSegue. I'm not sure why this is, and I'd like to have the UIStoryboardSegue value.

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
}
like image 295
Chewie The Chorkie Avatar asked Dec 06 '25 11:12

Chewie The Chorkie


1 Answers

You need

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

Getting the segue itself is meaningless. You only need to know the segue identifier. Also, if you need to make this the decision then replace

if debug_tutorialAllowCaptureBtnActions == false {
    return false
}

with

return tutorialAllowCaptureBtnActions 
like image 182
Sh_Khan Avatar answered Dec 08 '25 00:12

Sh_Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!