Chapter 7. Capturing user input: adding text boxes
This chapter covers
- Creating a new app that shows what’s typed into a field
- Capturing user ideas with text boxes
- Connecting objects with actions and outlets again
- Chunking code for a function
You’re going to create another app in this chapter, but this time you’ll provide a box the user can type in. After typing text, the user will tap a button, and whatever the user typed in the box will appear down below. Such boxes, called text boxes (or UITextFields for single lines of text and UITextViews for multiple lines of text), are used throughout iPhone and iPad programming. You’ve probably seen them numerous times but may not have known that they were called text boxes. Figure 7.1 shows an example.
When you create a new event in the Calendar app on your iPhone, the fields where you type the event’s title and location are text boxes. Text boxes are important components to learn, so let’s get started.
As you know, the best way to start any new project is with pseudocode, so let’s write down the steps you need to create this app:
- Create a new single-view application.
- Add a button and a label to the view.
- Add a text box to the view.
- Connect the button, label, and text box to the code (wire them up), and test the app.
- Add code to change the label, and test the app.
- Comment the code.
Let’s get started.