Search code examples
iosobjective-cuiviewcontrollerembeduistoryboard

iOS how to get a reference to a view controller embedded in a storyboard container with a segue?


I have a storyboard and a view controller with a container view. Within a storyboard I've defined a connection from the container to another view controller using "Embed" segue. How can I get a reference to the embedded view controller from within a parent view controller?

I've created a reference to the container, but see that it is just a UIView

Here's the segue I'm using enter image description here

enter image description here


Solution

  • you must implement the prepareForSegue in main ViewController and specify an identifier in your StoryBoard.

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        // Make sure your segue name in storyboard is the same as this line
        if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
        {
            // Get reference to the destination view controller
            YourViewController *vc = [segue destinationViewController];
    
        }
    }