Of course, the preferences settings are of little use if you can't programmatically access them from within your application. In the following sections, you modify the application so that you can load the preferences settings as well as make changes to them programmatically.

First, use the following Try It Out to prepare the UI by connecting the necessary outlets and actions.

TRY IT OUT: Preparing the UI

  1. Using the project created in the previous section, select the ApplicationSettingsViewController.xib file to edit it in Interface Builder.
  2. Populate the View window with the following views (see Figure 9-11):
    • Round Rect Button
    • Label
    • Text Field
    • Picker View
  3. In Xcode, insert the following code that appears in bold into the ApplicationSettingsViewController.h file:
    #import <UIKit/UIKit.h>
    @interface ApplicationSettingsViewController : UIViewController
        <UIPickerViewDataSource, UIPickerViewDelegate> {
            IBOutlet UITextField *loginName;
            IBOutlet UITextField *password;
            IBOutlet UIPickerView *favoriteColor;
    @property (nonatomic, retain) UITextField *loginName;
    @property (nonatomic, retain) UITextField *password;
    @property (nonatomic, retain) UIPickerView *favoriteColor;
    -(IBAction) loadSettings: (id) sender;
    -(IBAction) saveSettings: (id) sender;
    -(IBAction) doneEditing: (id) sender;


    FIGURE 9-11

  4. In Interface Builder, connect the outlets ...

Get Beginning iOS 5 Application Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.