Guidelines for viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear Guidelines for viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear ios ios

Guidelines for viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear


From UIViewController

viewWillAppear:

This method is called before the receiver’s view is about to be displayed onscreen and before any animations are configured for showing the view. You can override this method to perform custom tasks associated with presenting the view. For example, you might use this method to change the orientation or style of the status bar to coordinate with the orientation or style of the view being presented. If you override this method, you must call super at some point in your implementation.

viewWillDisappear:

This method is called in response to a view being removed from its window or covered by another view. This method is called before the view is actually removed or covered and before any animations are configured.

Subclasses can override this method and use it to commit editing changes, resign the first responder status of the view, or perform other relevant tasks. For example, you might use this method to revert changes to the orientation or style of the status bar that were made in the viewDidDisappear: method when the view was first presented. If you override this method, you must call super at some point in your implementation.

viewDidAppear:

You can override this method to perform additional tasks associated with presenting the view. If you override this method, you must call super at some point in your implementation.

viewDidDisappear:

You can override this method to perform additional tasks associated with dismissing or hiding the view. If you override this method, you must call super at some point in your implementation.

For further information you may check View Controller Programming Guide for iOS


An addition to the answer: You should invoke methods like super viewWillAppear: at the beginning of your implementation, and invoke viewDidAppear: at the end of your method. Superclass should begin with the initialisation and should be last to terminate.