Search code examples
iosobjective-cchildviewcontroller

Can not add a ChildViewController in Current Controller


I took 2 UIViewController HomeView and ViewMyStuff in Storyboard.

I am adding ViewMyStuff Controller in HomeView. In HomeView's ViewDidLoad, written below in my code.

- (void)viewDidLoad
{
    ViewMyStuff *vwMyStuff = [self.storyboard   instantiateViewControllerWithIdentifier:@"viewreportvc"];
    [self addChildViewController: vwMyStuff];
    [vwMyStuff didMoveToParentViewController:self];
}

vwMyStuff controller is not added in HomeViewController. Is there anything I missing? Please help

Thanks.


Solution

  • You need to add subView of your ViewMyStuff *vwMyStuff viewController.

    - (void)viewDidLoad
        {
            ViewMyStuff *vwMyStuff = [self.storyboard   instantiateViewControllerWithIdentifier:@"viewreportvc"];
            [self addChildViewController: vwMyStuff];
            [vwMyStuff didMoveToParentViewController: self];
            [self.view addSubview:vwMyStuff.view];
        }
    

    Hope it works for you!!