0

In ios, when AViewController launches another ViewContoller (BViewController), AViewController's preparedForSegue() will get calls and " segue.destinationViewController" will be a reference to BViewController.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
      segue.destinationViewController  
}

My question is if BViewController 'Back' to AViewController, which method of AViewController will get call, and AViewController knows it comes from BViewController?

hap497
  • 154,439
  • 43
  • 83
  • 99

2 Answers2

0

You need to implement delegate methods for that. Google it for more info related to delegate methods.

Sourav Gupta
  • 762
  • 11
  • 13
0

It depends on how you go back. If you use an unwind segue, a method you need to write in the controller you go back to (A) has UIStoryboardSegue as its argument, so you can get the source view controller from that. If you're not using an unwind segue, then you should use a delegate protocol to tell A that it came from B.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Thanks. I have read this thread about using unwind segue http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them. I am using Storyboard in xcode 6, I can't drag the segue from my source view to the exit button. I am back from the 'Back' button in Navigation bar in my Navigator Controller – hap497 Sep 21 '14 at 16:21
  • @hap497, you can't use the standard back button to do this, since it has a specific function; you would have to create your own left bar button item, and drag from it to the exit icon. If you want to use the back button, you would have to use a delegate method that you call in B's viewDidDisappear method to tell A, that it (B) is causing you to come back on screen. – rdelmar Sep 21 '14 at 17:16