Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode storyboard Container View - How do I access the viewcontroller

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:

enter image description here

And its referenced in my .h file as:

enter image description here

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.

like image 233
Justin808 Avatar asked Nov 07 '12 17:11

Justin808


People also ask

How do I add a ViewController to a storyboard?

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.


1 Answers

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.

like image 98
DAXaholic Avatar answered Oct 15 '22 14:10

DAXaholic