0

Am I able to know which segue has just been performed/popped?

For example I have 2 controllers:

  • View Controller A: Have 1 button that navigates to View B.
  • View Controller B: Have back button to View A.

I want in View A can detect that the View B just been popped out from stack, so I can do something in ViewWillAppear.

Can I do it?

Rendy
  • 5,572
  • 15
  • 52
  • 95

1 Answers1

0

You can name the segue and then implement prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) method, where you check the identifier if the segue. If it's the segue from ControllerA to ControllerB, just setup some flag that you will check in the viewWillAppear method.

Something like this:

var pushedB = false

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "mySegueName" {
        pushedB = true
    }
}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    if pushedB {
        pushedB = false
        // TODO your action
    }
}
Pavel Smejkal
  • 3,600
  • 6
  • 27
  • 45
  • Yes, but is there any way? It seems I can't find delegate methods that called for returning from segue. – Rendy Dec 01 '15 at 06:25
  • There is nothing like "return from segue". Segue object just encapsulates the operation of transitioning from one controller to another. In the show segue it basically takes the two controllers and decides whether it will do presentModal or push... – Pavel Smejkal Dec 01 '15 at 06:28
  • http://stackoverflow.com/questions/12380905/ios-how-to-detect-programmatically-when-top-view-controller-is-popped – ZHZ Dec 01 '15 at 06:57