Jakub
Jakub

Reputation: 13860

Get container VC instead of view

I'm a little confused how containers works. I have containers: enter image description here

And i try to manage this in my MainViewController. But when i control-drag it into my .h file i'm getting

@property (weak, nonatomic) IBOutlet UIView *liveContainer;

Why this is an UIView class? This mean that is self.view my BaseButtonContainerView? But I have BaseButtonContainerViewController, and in debug i see that viewDidLoad is called. Can i get access to BaseButtonContainerViewController methods from MainViewController?

Upvotes: 0

Views: 212

Answers (2)

rdelmar
rdelmar

Reputation: 104092

The controllers that are embedded in the container views are child view controllers of MainViewController, so you can access them with self.childViewControllers. That will give you an array of all your children, so you have to use objectAtIndex: to get to any one particular controller. The container views are just normal UIViews. The storyboard is just doing the work of setting up the child view controllers for you. What you get is the same as if you had used the custom container controller api to add the children yourself in code (with addChildViewController: and didMoveToParentViewController:, followed by adding the child's view to self.view or to a subview of self.view).

Upvotes: 0

Firo
Firo

Reputation: 15566

Storyboards like to do everything in the prepareForSegue so just assign your segue an identifier. In this case we'll assume you set it to baseButtonContainerSegue in IB. Then in prepareForSegue use :

- (void) prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"baseButtonContainerSegue"]) {
        self.liveContainer = segue.destinationViewController;
    } 
}

Just make sure that you have a UIViewController property liveContainer, (specifically in your case you would want to have a BaseButtonContainerViewController property). I am not exactly sure why you have to do it this way but I am guessing it has something to do with memory management. Say you leave that screen and your containers are deallocated. Then when you go back you may lose your connection to them. This way the segues would be called again and you could grab them as properties. Again, I am not sure, so if someone else does please enlighten me!

Upvotes: 2

Related Questions