Appearing and Disappearing Views

UIViewController has several methods that get called at certain times:

viewWillAppear:

when its view is about to be added to the window

viewDidAppear:

when its view has been added to the window

viewWillDisappear:

when its view is about to be dismissed, covered, or otherwise hidden from view

viewDidDisappear:

when its view has been dismissed, covered, or otherwise hidden from view

These methods are useful because a view controller is only created once, but its view usually gets displayed (and dismissed or hidden) several times. You often need a way to override the default behavior at these times in the life of view controller. For example, you may want to do some sort of initialization each time the view is moved on ...

Get iOS Programming: The Big Nerd Ranch Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.