P
P
pinapple2015-07-07 12:58:40
Objective-C
pinapple, 2015-07-07 12:58:40

Explain why this method is needed?

When I add childController as a child controller, why do I need to execute the didMoveToParentViewController:self method at the end? Here is part of the code

[self addChildViewController: childController];
[self.view insertSubview: childController.view atIndex:0];
[childController didMoveToParentViewController:self];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
An, 2015-07-07
@pinapple

This method signals to the child ViewController that its "transition" to the parent container is complete.
This way you can react to the end of adding your controller to the hierarchy. Now, it seems like this method does nothing for the base UIViewController. However, YOU MUST call it when implementing your custom container. Firstly, no one guarantees that in ios> 9 he will not start doing something. Secondly, there are a lot of third-party libraries / pods where these methods can be overridden in custom components. And now, if you shove them into your custom container and do not call didMoveToParentViewController, then there will be undefined behavior

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question