iPhone Application Development For Dummies Cheat Sheet - dummies
Cheat Sheet

iPhone Application Development For Dummies Cheat Sheet

From IPhone Application Development For Dummies, 4th Edition

By Neal Goldstein

To develop iPhone apps, you have to be able to navigate the tricky Xcode Workspace window, and you’ll find a guide here. This cheat sheet also helps you cut through some common confusion over what iPhone view controller method to use.

Navigating the Xcode Workspace Window for iPhone App Development

Xcode is essential for iPhone app development. And command central for Xcode is the Workspace window, where you perform all the tasks you need to do to develop your iPhone app. The Workspace window consists of the following:

  • The toolbar

  • An optional tab bar

  • Areas

The Workspace is divided into the following four areas (outlined in blue and identified in blue text in the figure):

  • Editor area (always shown)

  • Navigator area

  • Utility area

  • Debug area

Areas are toggled on and off by using the View selector (outlined in blue in the top right of the figure). Xcode also has three editor panes: the Standard editor pane, the Assistant editor pane, and a Version editor pane. These are selected in the Editor selector (outlined in green to the left of the View selector).


iPhone App Development: Understanding View Controller Methods

iPhone Application Developers struggle with knowing what view controller methods to use, and when. Picking the wrong method to refresh your user interface can result in an iPhone app that disappoints the users.

To understand when to do something in the UIKit framework, you need to know when messages are sent, especially to view controllers. View controllers have a life cycle just as applications do, and certain messages are sent as views that are displayed and hidden.

The two methods you need to know about in order to work with views are

  • viewDidLoad

  • viewWillAppear:

The following table summarizes what you should do in which method:

Method When to Send It What to Use It For
viewDidLoad After the view controller has loaded its associated views into
Perform additional view initialization on views loaded
from the storyboard or nib file. For example, if you are displaying
some static text, load that text here.
viewWillAppear: When the view is about to become visible Do the things that are necessary to present the view.
For example, if you are displaying the location of the nearest book
store that carries iPhone Application Development For
, update that information in this method.

The viewDidLoad message is sent to the view controller after the view controller has loaded its associated views into memory. This method is used to perform view initialization and is not necessarily called every time the view appears. If, for example, the user makes a selection in the view that causes a new view controller to load and slide its view into place, and the user then taps the Back button, this message is not sent when the originating view reappears. That is the job of viewWillAppear:.

The viewWillAppear: message is sent when the view is about to become visible. The first time it is sent is after the viewDidLoad message and then whenever the view reappears, such as when you tap the Back button, for example. You use this method to refresh your user interface, if needed, but not for initialization.