Simple rule I use is this. viewDidLoad
is when the view's resources are loaded. The view is not drawn onscreen yet. So calculations and code dealing with the geometry and visuals of the view should not be put here. They should be in the viewWillAppear
or viewDidAppear
method.
Also viewWillAppear can be called multiple times
- When a popover/modal view is displayed and remove
- When an alert view/actionsheet/uiactivityController's view is displayed and removed.
For these reason, viewWillAppear
should not contain codes that takes longer to finish. (at least the code running on the main thread). Neither should codes that only needs to be run once per view display.
There are more I am sure but these are simple to remember and I hope it helps.