Apple Documentation on UIViewController
says:
If you are implementing your own container view controller, it must call the willMoveToParentViewController:
method of the child view controller before calling the removeFromParentViewController
method, passing in a parent value of nil.
When your custom container calls the addChildViewController:
method, it automatically calls the willMoveToParentViewController
: method of the view controller to be added as a child before adding it.
If you are implementing your own container view controller, it must call the didMoveToParentViewController:
method of the child view controller after the transition to the new controller is complete or, if there is no transition, immediately after calling the addChildViewController:
method.
The removeFromParentViewController
method automatically calls the didMoveToParentViewController:
method of the child view controller after it removes the child.
Why should I call these methods? What does those methods do?
ProfileViewController *profile = [[ProfileViewController alloc] init];
profile.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self addChildViewController:profile];
[self.view addSubview:profile.view];
[profile didMoveToParentViewController:self];
My code works perfectly even though I remove the last line. Can someone please help me in this?
Thanks in advance