O'Reilly logo

Beginning iOS 5 Application Development by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

PROGRAMMATICALLY ACCESSING THE SETTINGS VALUES

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;
    
    @end

    image

    FIGURE 9-11

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required