What exactly is a purpose of calling func didMove(toParent parent: UIViewController?)
?
From apple documentation it says:
If you are implementing your own container view controller, it must call the didMove(toParent:) 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 addChild(_:) method.
The removeFromParent() method automatically calls the didMove(toParent:) method of the child view controller after it removes the child.
It seems like the function updates the transition of a viewcontroller, but I can't fully grasp the idea behind calling it. What would happen if I don't call it?
A UIViewController is an object which manages the view hierarchy of the UIKit application. The UIViewController defines the shared behavior and properties for all types of ViewController that are used in the iOS application. The UIViewController class inherits the UIResponder class.
You use view controllers to manage your UIKit app's interface. A view controller manages a single root view, which may itself contain any number of subviews. User interactions with that view hierarchy are handled by your view controller, which coordinates with other objects of your app as needed.
If you don't call it the child view controller won't be able to detect that it did move to the parent view controller. This may be important. Sometimes you need to do something in the child controller exactly after moving to the parent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With