Skip to content

Instantly share code, notes, and snippets.

@peterfriese
Created November 30, 2011 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterfriese/1410770 to your computer and use it in GitHub Desktop.
Save peterfriese/1410770 to your computer and use it in GitHub Desktop.
Do I need to call didMoveToParentViewController in my custom container view controller? Yes, you do, the doc says it
// Taken from UIViewController.h, code is (c) Apple
/*
These two methods are public for container subclasses to call when transitioning between child
controllers. If they are overridden, the overrides should ensure to call the super. The parent argument in
both of these methods is nil when a child is being removed from its parent; otherwise it is equal to the new
parent view controller.
addChildViewController: will call [child willMoveToParentViewController:self] before adding the
child. However, it will not call didMoveToParentViewController:. It is expected that a container view
controller subclass will make this call after a transition to the new child has completed or, in the
case of no transition, immediately after the call to addChildViewController:. Similarly
removeFromParentViewController: does not call [self willMoveToParentViewController:nil] before removing the
child. This is also the responsibilty of the container subclass. Container subclasses will typically define
a method that transitions to a new child by first calling addChildViewController:, then executing a
transition which will add the new child's view into the view hierarchy of its parent, and finally will call
didMoveToParentViewController:. Similarly, subclasses will typically define a method that removes a child in
the reverse manner by first calling [child willMoveToParentViewController:nil].
*/
- (void)willMoveToParentViewController:(UIViewController *)parent __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
- (void)didMoveToParentViewController:(UIViewController *)parent __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment