Call loadView explicitly - good / bad?

Is there any harm when calling loadView explicitly?

I need to get to the server and get the data for display, and this data will be changed depending on some user actions in this view. I make a server call in my loadView method and pass the appropriate parameters. Now that the user conditions are changing, I call [self loadView] with the changed parameters. Do you see any problem here?

+4
source share
4 answers

Well, I think the Apple documentation says it all:

loadView Creates a view that the controller controls.

- (void) loadView You should never call this method directly.

+12
source

Instead, call the UIViewController view method. This will call loadView if necessary.

+5
source

Bad Because:

  • LoadView is provided so that you add things to the view programmatically; It is explicitly designed for synchronization;
  • calling loadView several times can cause a memory leak, as loaded objects load again.

Configure the view to have two configurations, telling the user that he is downloading from the server or available for input, even if he has only a visible or no spinner. Create a means of switching between them. Use it to contact your user.

Trying to undermine the intended patterns will always lead you along the road where, in the absolute best of times, most things seem to work, and you are fooling yourself that another hack will solve the final problem, and at worst, nothing else works, and you spent so much time to pull yourself out altogether, that getting out of it means starting all over again anyway.

+1
source

I made another server call, retrieved the data, updated the modal, and then updated the view. NO CALL TO loadView !!!

0
source

Source: https://habr.com/ru/post/1345175/


All Articles