Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is viewWillAppear called?

By my count, the only two instances when viewWillAppear is called is when you initialize your view controller, or when you pop off the view controller that's on top of it on the navigation stack (ie pushing the back button on the viewcontroller ahead of it). Are there any other instances when viewWillAppar is called? I don't believe it's called when the app becomes active. Interested to hear some responses on this.

like image 754
Ser Pounce Avatar asked Jan 11 '12 06:01

Ser Pounce


People also ask

Is viewWillAppear always called?

Always called after viewDidLoad (for obvious reasons, if you think about it), and just before the view appears on the screen to the user, viewWillAppear is called.

What triggers viewWillAppear?

The method viewWillAppear: is triggered in response to a change in the state of the application, indicating that the view controller is becoming “active.”

Why viewWillAppear is not called?

The Simple Answer. The technical reason for when viewWillAppear gets called is simple. Notifies the view controller that its view is about to be added to a view hierarchy. It can't be any view hierarchy — it has to be the one with a UIWindow at the root (not necessarily the visible window).

What is the difference between viewDidLoad and viewWillAppear?

The difference between viewDidAppear and viewDidLoad is that viewDidAppear is called every time you land on the screen while viewDidLoad is only called once which is when the app loads. Let me show you a simple experiment to help you to understand how it works.


1 Answers

viewwillappear method is called as and when the view controller's view is added to the window. ( if the view is already in the window and is hidden by another view, this method is called when the view is once again revealed). The method is a notification to the view controller that the view is about to become visible. You can override this method to make any customizations with presenting the view.

like image 99
sahiti Avatar answered Oct 06 '22 11:10

sahiti