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];
insertSubview:atIndex
instead of justaddSubview
? – BitterrootaddSubview
adds at the end, and yourinsertSubview
adds to the start, but that would only make a difference in the UI if there were other views already on the parent view controller. – GaetaviewDidAppear
andviewWillAppear
is only called once, just likeviewDidLoad
". Are you saying that the parent view controller is definitely getting it but the child view controllers aren't? Or are you saying that the child only gets it once (in which case I don't understand the question at all)? – GaetaviewWillAppear
, fine, (unless I use that silly method I described in my answer below), so I'm perplexed. I don't know how complicated your project is but maybe you can try creating a new blank project with just the one trivially simple child view controller, and see if you still see the problem (that should be a 5-10 minute exercise). Assuming you don't, then maybe you can slowly add complexity to this test project (so it slowly, step by step, until you see the problem manifest itself again). – GaetaviewDidAppear
in B again. Because B is a container, it's assumed that it was (and still is) visible. Generally when I do containment, the child views don't take up the entire screen (because I have some control on the parent to dictate which child will be active), so the notion of not getting anotherviewWillAppear
orviewDidAppear
is intuitive. When your child is taking up the whole screen, I can understand why you would have expected the appearance methods, but you won't. – GaetaremoveFromParentViewController
? According to the docs, "these methods are not intended to be called by clients [the child view controllers] of your container class". Thus, if your parent view controller B is removing child C, then you probably don't need any notification in B that it has appeared (because it knows, it just did it itself). – GaetaviewWillAppear
. – Gaeta