Junior — Middle
Is it possible for the viewDidAppear method to trigger without a prior call to viewWillAppear?
sobes.tech AI
Answer from AI
In the normal lifecycle of a UIViewController, the method viewWillAppear is called before viewDidAppear. However, there are situations where viewDidAppear may be triggered without a prior call to viewWillAppear:
- If the controller is already on the screen and
viewDidAppearis called again (for example, when returning from a modal presentation), butviewWillAppearis not called because the view did not disappear. - Due to programming errors or non-standard manipulations of the controller hierarchy.
In the standard scenario, viewWillAppear is always called before viewDidAppear, so if this does not happen, it is worth checking the logic of controller presentation and their lifecycle.