I'm trying to use storyboard and get things working properly. I've added a a Container View to one of my existing views. When I try to add a reference to this in my view controller .h
file (ctrl-drag), I get a IBOutlet UIView *containerView
. How do I get a reference to the container view's view controller instead? I need the container view controller so I can set it's delegate to my view's controller so they can "talk" to each other.
I have my story board setup as:
And its referenced in my .h file as:
Notice in the .h that is is a UIView, not my InstallViewController for the view. How do I add a reference to the view controller? I need to be able to set its delegate.
To create a new view controller, select File->New->File and select a Cocoa Touch Class. Choose whether to create it with Swift or Objective-C and inherit from UIViewController . Don't create it with a xib (a separate Interface Builder file), as you will most likely add it to an existing storyboard.
There is another solution by specifying an identifier for the embed segue(s) and retrieve the corresponding view controllers in method prepareForSegue:
The advantage of this way is that you needn't rely on a specific order in which your child view controllers are added due to the fact that each child view controller is embedded via an unique segue identifier.
Update 2013-01-17 - Example
- (void) prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender { // -- Master View Controller if ([segue.identifier isEqualToString:c_SegueIdEmbedMasterVC]) { self.masterViewController = segue.destinationViewController; // ... } // -- Detail View Controller else if ([segue.identifier isEqualToString:c_SegueIdEmbedDetailVC]) { self.detailViewController = segue.destinationViewController; // ... } }
c_SegueIdEmbedMasterVC
& c_SegueIdEmbedDetailVC
are constants with the corresponding ID of the segue IDs defined in the storyboard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With