viewDidLoad
method is called first time when UIViewController
is first loaded and when it pop and then you reenter in it at that time viewDidLoad
is called. So if you want to load the API only once then viewDidLoad
is the best place to call an API.
viewWillAppear
called every time when you enter in that UIViewController
and it is the place load the API when you want to get refreshed data (updated data).
viewDidAppear
also called like viewWillAppear
but bit late called than viewWillAppear
so if you want to call the API every time than the best place is viewWillAppear
method.
Because viewDidAppear
method called late from viewWillAppear
method and you are just requesting the API so the response of API may be late and If your UI change based on API response then it will stuck the application UI so there is a best place to call API either viewDidLoad
& viewWillAppear
methods.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…