Apple says in the viewWillAppear
Documentation
This method is called before the receiver’s view is about to be added to a view hierarchy and before any animations are configured for showing the view.
What does this sentence means
before any animations are configured for showing the view.
I am actually expecting the viewWillAppear
to be called when the view is added in to the view hierarchy but when i come back from the background app to the foreground it also calls viewWillAppear
when the view controller is already in the view hierarchy. Does it have to do some thing with the sentence
before any animations are configured for showing the view.
also the similar thing happens if i switch the tabs or some modal view controller
is dismissed from my view.
The most classic and reliable method for the purpose you need is viewDidLoad
.
viewWillAppear
/viewWillDisappear
and similar methods are designed to be called multiple times, viewDidLoad
- only once, when the view first loads itself on the navigation stack, for example.