ViewWillAppear and loadView for building hierarchy

I am building my view hierarchy using code and would like to know whether it is better to create the entire hierarchy in loadView when the request is requested from my controller, and then animate the views on the screen in the viewWillAppear method, or if it is better to keep things simpler, but potentially requires more release and memory allocation by building the entire hierarchy in viewWillAppear.

I understand that the controller calls loadView to create the view for the first time it needs it, and then saves it as long as it can, so you can leave and go back to that controller and animate it in the views, but you don’t need to recreate and attach them through viewWillAppear.

Basically, it seems to me useless to separate the views in the loadView, and then translate (and sometimes update the contents inside) them into viewWillAppear and wonder if the advantages of preserving the views improve simplicity by simply recreating them (and therefore reinitializing them and avoiding them any un reset values).

+3
source share
1 answer

loadView It is called only once at creation and must have a continuous contour to create a view.

viewWillAppear:(BOOL)animatedcalled each time a view is displayed. If your opinion is saved, you can update / set your data. (Your UIButtons, UILabels, ... are already allocated to loadView, you just installed the content here.)

+2
source

All Articles