Manish Patel Manish Patel - 3 months ago 9
Objective-C Question

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 HomeView viewcontroller. Is there anything I missing? Please help

Thanks.

Answer

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!!