0

When you have an embedded view controller inside a container, how can you detect when it is about to perform a segue?

For example:

Storyboard

I want to detect when a segue happens within the embedded view controller from the view controller containing the container.

BytesGuy
  • 4,097
  • 6
  • 36
  • 55

2 Answers2

2

Since the segue management is done by the embedded view controller, a solution would be to establish a delegate mechanism between your embedded view controller and the containing view controller, so that the containing view controller is informed if a segue is performed.

If you don't want your view controllers know each other, you could also send notifications through the NSNotificationCenter from the prepareForSegue method and react to them in the containing view controller.

Christian
  • 357
  • 3
  • 13
  • After a bit of debugging I found that (as my app is all based on navigation controllers) the notification `UINavigationControllerWillShowViewControllerNotification` was sent each time, so I added an observer for it. I am picking your answer as mentioning notifications got me thinking, thanks! – BytesGuy Jan 28 '14 at 14:46
0

In the embedded view you can use the - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender method to notify the container view. I assume that the segues have attached an indentifier in storyboard.

alexcristea
  • 2,316
  • 16
  • 18
  • What I mean is to detect it in the view controller that has the container – BytesGuy Jan 28 '14 at 11:18
  • As @Christian says in his answer you will have to use a notification or a delegate. Here is a similar question: http://stackoverflow.com/questions/14968321/container-view-controllers-notify-parent-of-action – alexcristea Jan 28 '14 at 12:13