Creating and Using Outlets
Where actions receive messages, outlets link code to an object on the screen. After you create an outlet, you can use it to read and set the object’s properties. In this example, we’ll create an outlet to a text field—a small text box—and use it to change the text in the box when a button is tapped.
To work through the steps, you can either carry on using the project created earlier in this chapter or create a new project and repeat the steps you followed to create a button with a connection to an (IBAction). We’ll use the button message handler to trigger a change in the text.
Creating an outlet
Follow these steps:
1. Starting with the previous project or a duplicate, select a text field from the Object Library in the Utilities pane, and drag it onto the view in the nib. Optionally, you can use the guide lines in IB to center the text field. The nib file should look like Figure 8.14.
Review the steps earlier in this chapter if you’re not sure how to find the Object Library and drag objects from it into a view.
8.14 Adding a text field to a view.
2. Arrange the editor windows so you can see the ViewController header file in one pane and the corresponding nib file in the other.
3. Hold down the Ctrl key and drag a link from the text field to the ...