Information Technology Reference
In-Depth Information
Filling out an action stub
The app is nearly finished. The missing feature is custom code in the action stub that updates the label when
the button is tapped.
In the implementation file, add this code between the curly brackets in the IBAction stub, as shown in Fig-
ure 7.31:
if ([theLabel.text isEqualToString: “@This is off”])
theLabel.text = @”This is on”;
else
theLabel.text = @”This is off”;
This code reads the current label text and updates the text to an alternate message when the button is tapped.
The key point is that the outlet allows the label text to be read and written.
You can read and write any property. For example, you could change the label's position or the size or color of
the text. This example makes a trivial change to the label text, but more complex objects work in the same way.
For example, you can read a block of text entered by a user from a more complex text field object. You also can
read or write image data to an image view.
Testing the app
Select the iPhone Simulator, and click the Build & Run arrow at the top left of the Xcode toolbar. The app
should build and run in the Simulator window. Clicking the button in the UI toggles the label text between
“This is off” and “This is on.”
Search WWH ::




Custom Search