I get used to put either of viewWillAppear
and viewDidLoad
, it's OK until know. However I'm thinking there should be some rules that guide when to put into viewWillAppear
and when to put into viewDidLoad
?
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
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.