didMoveToParentViewController and willMoveToParentViewController

Basically, they don't do anything that you can notice in the interface. "However, any subclass allows them to be overridden, so if you don't call them, you won't break a bare UIViewController, but you will break subclasses that rely on it (for instance: say a subclass wants to release an object when it is removed from a parent view controller, if you don't call the method, then it will never release the object)." as it was explained in the comments here.


These methods are used because it is a rule to be followed when adding or removing a child view controller. Before adding a child view controller willMoveToParentViewController method should be called first followed by didMoveToParentViewController method. While removing child view controller from parent view controller these methods are to be called in reverse order.

addChildViewController: automatically calls [child willMoveToParentViewController:self]. So one should call didMoveToParentViewController after addChildViewController:. Similarly removeFromParentViewController: automatically calls [child didMoveToParentViewController:nil]. So one should call willMoveToParentViewController: before removeFromParentViewController: