Check if you can use unwind segment before using push segue

In navigation using segues from the root controller, we can press controller A or B.

From A, we can press C, which can press B, which later can relax to A, to restart the process.

From B, we can press A, which can press C, which can later relax to B, to restart the process.

In B, we have a button that says “Go to A,” which should unwind or press controller A, depending on the scenario.

diagram

How can I easily find out if I can relax before formatting a push sega?

navigationController, , C . segues, :

B A , else A

, , , B A navigationController?

+4
1

Swift:

  • , UINavigationController
  • unwindToXXX: XXX,
  • YYY, , XXX, segues unwindToXXX showXXX

gotoController("unWindToXXX", "showXXX")

func gotoController(unwind: String, show: String) {
    let action = Selector(unwind + ":")
    if let target = navigationController?.viewControllerForUnwindSegueAction(action, fromViewController: self, withSender: self)
    {
        assert(target.canPerformUnwindSegueAction(action, fromViewController: self, withSender: self))
        performSegueWithIdentifier(unwind, sender: self)
    } else {
        performSegueWithIdentifier(show, sender: self)
    }
}
0

Source: https://habr.com/ru/post/1531775/


All Articles