I am making iPhone app on swift,here ViewDidAppear and ViewWillAppear is being called multiple times on one viewDidLoad in ios swift app?
please help me.
I am making iPhone app on swift,here ViewDidAppear and ViewWillAppear is being called multiple times on one viewDidLoad in ios swift app?
please help me.
Whenever You push a viewController, It will call viewDidLoad then viewWillAppear and last viewDidAppear. But if you are coming back to viewController only viewWillAppear and viewDidAppear will call.
View will call these two (viewWillAppear & viewDidAppear) every time, whenever this viewController shows on every condition
i. On push - viewDidLoad after it, viewWillAppear & viewDidAppear.
ii. On back or pop - No viewDidLoad will call, Only viewWillAppear & viewDidAppear.
iii. On become active state - No viewDidLoad will call, Only viewWillAppear & viewDidAppear.
If you are not familiar with the UIViewController life cycle I really recommend you to start here Apple documentation and here.
But in a very short answer
The method viewDidLoad
- This method is called after the view controller has loaded its view hierarchy into memory. This method is called regardless of whether the view hierarchy was loaded from a nib file or created programmatically in the loadView method. You usually override this method to perform additional initialization on views that were loaded from nib files.
The methods ViewDidAppear
and ViewWillAppear
as they sound to you, called every time the view Appear on the screen.
This image (from Apple documentation) shows the valid state transitions between various view ‘will’ and ‘did’ callback methods