Do the Right Thing at the Right Time

When it comes to the view controller, you need to be aware of two methods, and you need to know what to do in each method.

The viewDidLoad message is sent to a view controller when the view has been loaded and initialized by the system. It is sent only when the view is created — and not, for example, when your app returns from background or when a view controller is returned to after another view controller has been “dismissed.”

The viewWillAppear: message, on the other hand, is sent whenever the view appears, including when the view reappears after another view controller is “dismissed.”

Do view initialization in viewDidLoad, but make sure that anything you do to refresh a view whenever it appears is done in viewWillAppear:.

Get iPad Application Development For Dummies, 3rd 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.