I have a storyboard set up in XCode and have a MainViewController. In the MainViewController I have added a ContainerView which naturally creates a Segue with another VIewController.
In my MainViewController.m file I have set up data and want to link this data to a label in the ContainerView however I thought I could click on the File's Owner and do this but of course I can't because they are 2 different viewcontrollers now.
Can someone please help me because I'm struggling with this. There must be an easy way but I can't crack it!
Thank you
You can use prepareForSegue just like any other two controllers -- that method will be called after the two controllers are instantiated, but before either viewDidLoad runs. The other way to do this is to use the parent controller's childViewControllers property (the embedded controller is a child). So, the child will be self.childViewControllers[0].
After Edit:
Of course, you have to change the names to what you have. Make sure the name you give to the segue in IB matches the one you check for in the if statement. In this example labelString is a string property you set up in your embedded controller. Then in that controller's viewDidLoad method, you can set the value of the label with that string.
This is pretty much the same answer as the one by rdelmar only in Swift.
"EmbedSegue"
has to the segue identifier you set in Interface Builder.Answer for Swift 4:
I should also mention that because you are using a Container view,
prepareForSegue
will be triggered when you'll present theViewController
that holds the Container.