Load UIViewController

0

I have a UIViewController with the Black Background where it would be my main UIViewController (where the menu is and etc) and I do this:

CredenciaisViewController *obj = [self.storyboard instantiateViewControllerWithIdentifier:@"Credencial"];    
[_viewContainer addSubview:obj.view];
    _viewContainer.alpha = 1;

The CredentialsViewController has the red background and I load it into a UIView that is in my main UIViewController, but when it loads inside the view it gets half white and the UiButtons when they are on the white do not work.

Why does this happen? And how do I resolve?

    
asked by anonymous 08.10.2014 / 16:23

1 answer

2

You can not add a UIViewController as subview of another UIView . For this purpose, there is Custom Container .

Then you can add it using the addChildViewController: childController in your UIContainerView and not UIView as in your example.

In the interface builder you can find it, like this:

Dynamically,dosomethinglikethisintheactionofyourUIButton:

-(IBAction)mostrarCredenciais:(id)sender{CredenciaisViewController*credenciaisView=[self.storyboardinstantiateViewControllerWithIdentifier:@"Credencial"];

    [self addChildViewController:credenciaisView];
    [credenciaisView didMoveToParentViewController:self];
    credenciaisView.view.frame = self.containerView.bounds;
    [self.containerView addSubview:credenciaisView.view];
}

So you do not need to connect to the storyboard of the container with UIViewController . Just plug in the IBOutlet (which is a UIView normal), which in my example is containerView .

    
08.10.2014 / 17:40