调用func didMove(toParentparent: UIViewController?)的具体目的是什么?
?
从苹果文档中可以看出:
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.
看起来该函数更新了 View Controller 的转换,但我无法完全理解调用它背后的想法。如果我不调用它会发生什么?
最佳答案
如果您不调用它, subview Controller 将无法检测到它确实移动到父 View Controller 。这可能很重要。有时您需要在移动到父 Controller 后立即在子 Controller 中执行某些操作
关于ios - 为什么我们必须在调用 addChild(UIViewController) 之后调用 func didMove(toParent Parent : UIViewController? ) ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57001422/