What's the proper way to add a view controller to the view hierarchy?

后端 未结 1 1446
渐次进展
渐次进展 2020-12-18 05:35

I have a view controller (A) that loads a view controller (B) and uses it\'s view in my view hierarchy. If I add B\'s view to A\'s view hierarchy, and I don\'t manually for

相关标签:
1条回答
  • 2020-12-18 06:08

    There is no magic solution here. The correct solution is to manually send these messages.

    The viewWillAppear:/viewDidAppear: and viewWillDisappear:/viewDidDisappear: messages are the only messages you need to manually send to the child view controller.

    You should implement all four of these methods in the parent view controller and send the same message to the child view controller whenever the parent receives the message and the child is loaded.

    In addition, when you add the child view controller's view, you should send the viewWillAppear:/viewDidAppear: messages if the parent's view.window is non-nil. When you remove the view, you should send the viewWillDisappear:/viewDidDisappear: messages if the parent's view.window is non-nil.

    0 讨论(0)
提交回复
热议问题