When is viewDidLoad called in a container environment?

让人想犯罪 __ 提交于 2019-12-11 03:44:26

问题


My situation looks like the following:

I have different container views. If the user triggers a tap event I create a new container and call a method on it, which sets the content of a child view controller. The problem I head was that the object (UIWebView in my case) was nat available at that time. The reason is that viewDidLoad hasn't been called at that time and the webview wasn't set up. Now I moved the initialisation of the webview in the constructor. This leads to my second issue:

On another container I load the same child view controller (with the web view on it). Because the bounds of the view are not available in the constructor I switched to auto layout. Now auto layout couldn't be applied because there was no superview. The cause of the issue was that viewDidLoad of the child view was called (where I set up my constraints) before it has been added to the container view. So there was no superview available regardles where I tried it to add as child view controller. Then I moved my auto layout setup into updateViewConstraints which works.

Now I'm wondering when viewDidLoad will be called. I cannot assume right after the initialization of the view controller, because that's not true. How could I reliable pass data to my child view controller when it's ready? Am I doing something wrong here?

When will viewDidLoad be called? Sometimes it is called right after initialization and sometimes not ...


回答1:


1)The view controller calls loadView method when its view property is requested but is currently nil. 2)After view is created view controller calls viewDidLoad method. 3)view property return created view

Summarising: viewDidLoad method called during first time you are requesting view property



来源:https://stackoverflow.com/questions/26652457/when-is-viewdidload-called-in-a-container-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!