USING THE KEYBOARD

In iPhone programming, the views most commonly associated with the keyboard are the Text Field and the Text View. When a Text Field is tapped (or clicked, if you are using the Simulator), the keyboard is automatically displayed. The data that the user taps on the keyboard is then inserted into the Text Field. The following Try It Out demonstrates this.

TRY IT OUT: Using a Text Field for Inputs

image

  1. Using Xcode, create a new Single View Application (iPhone) project and name it Keyboardlnputs. You will also use the project name as the Class Prefix and ensure that you have the Use Automatic Reference Counting option unchecked.
  2. Select the KeyboardInputsViewController.xib file to edit it using Interface Builder.
  3. Populate the View window with the Label and Text Field views (see Figure 6-1). Set the Label to display the text “Alphanumeric Input.”
  4. Press Command-R in Xcode to run the application on the iPhone Simulator. When the application is loaded, the keyboard is initially hidden; and when the user clicks the Text Field, the keyboard automatically appears (see Figure 6-2).

    image

    FIGURE 6-1

    image

    FIGURE 6-2

How It Works

The beauty of the iPhone user interface is that when the system ...

Get Beginning iOS 5 Application Development 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.