Ios – viewDidAppear not getting called

iosipadiphoneobjective c

In my main UIViewController I am adding a homescreen view controller as subviews:

   UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:vc];
        controller.navigationBarHidden = YES;
        controller.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
        [self addChildViewController:controller];
        [self.view insertSubview:controller.view atIndex:0];
        [controller didMoveToParentViewController:self];    

The issue is that viewDidAppear and viewWillAppear is only called once, just like viewDidLoad. Why is this? How do I make this work?

Basically inside vc I am not getting viewDidAppear nor viewWillAppear.

I also just tried adding the UIViewController without the navigation controller and it still doesn't work:

vc.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
        [self addChildViewController:vc];
        [self.view insertSubview:vc.view atIndex:0];
        [vc didMoveToParentViewController:self];    

Best Answer

In my case, viewDidAppear was not called, because i have made unwanted mistake in viewWillAppear method.

-(void)viewWillAppear:(BOOL)animated {
    [super viewdidAppear:animated]; // this prevented my viewDidAppear method to be called
}
Related Topic