Should EXPLICITLY call willMoveToParentViewController:(UIViewController *)parent & didMoveToParentViewController:(UIViewController *)parent?

petershine picture petershine · Nov 29, 2012 · Viewed 7.2k times · Source

In the WWDC 2012 Session titled The Evolution of View Controllers on iOS - (void)willMoveToParentViewController:(UIViewController *)parent and - (void)didMoveToParentViewController:(UIViewController *)parent have been mentioned to be used in custom container implementation for view transitions.

If I'm not mistaken, it seems to require to call these methods EXPLICITLY, either before - (void)removeFromSuperview or after - (void)addSubview:(UIView *)view

However, when I logged them inside sub class implementations, it shows that they have been called IMPLICITLY. They have been called at the right places automatically.

So, I'm a little confused if these methods ARE REALLY NEEDED to be called explicitly, like instructed in the WWDC Session, or it's ok not to follow it and clear out unnecessary lines of codes.

Answer

matt picture matt · Nov 29, 2012

Explained in my book:

http://www.apeth.com/iOSBook/ch19.html#_container_view_controllers

Basically one of the two is indeed implicitly called but the other you must call explicitly. It's maddening; I have to look up the rules every time.