iPhone Quickstart
This tutorial describes how to create an iPhone application using Xcode and Interface Builder. I’m assuming that you have installed Xcode and the iPhone SDK. The application prompts the user for a name and displays a message when the user touches a button.
To begin, start Xcode, and create a new view-based application:

Next, double-click on HelloViewController.xib. This will launch Interface Builder. Open the Library (Tools → Library) if it’s not already visible, and drag a Text Field, Round Rect Button, and Label onto the view window. Arrange them as they appear in the following screenshot. Double-click on the button to edit it’s text.

Next we need to add two instance variables and one method to the HelloViewController class. The two instance variables (outlets) will hold pointers to the UITextField and UILabel controls we added using Interface Builder. The method (action) will be wired up to execute in response to the user touching the Hello button. Go back to Xcode and edit your HelloViewController.h file to look like this:

Next, save everything (important!) and go back to Interface Builder. We need to tell Interface Builder to “wire up” our variables (outlets) and methods (actions) to the controls we placed on the view. To do this, control+click “File’s Owner,” drag to the text field, release, and select the outlet you want to attach. In this case, select “name.”

Do the same thing to attach the UILabel to the message outlet: Control+Click “File’s Owner,” drag to the label, release, and select message.
Now we need to attach the button to the hello: action. This is done similiarly to how we connected our outlets, except in the reverse direction. Control+click the button, drag to “File’s Owner,” release, and select the “hello:” action:

Now that we have our user interface wired up to our view controller, the only thing left to do is implement the hello: action. Open up the HelloViewController.m file in Xcode. You’ll notice a bunch of commented-out code and empty methods. These are all safe to delete. Edit the file so that it looks like this:

At this point, everything is ready to run. To recap, we have:
- Created an iPhone View-Based application.
- Used Interface Builder to add three controls to our view: a text field, a label, and a button.
- Added two outlets to our view controller: one called
namefor the text field, and another calledmessagefor the label. - Added an action called
hello:to our view controller. - Used Interface Builder to “wire up” our outlets and actions.
- Implemented the
hello:action in our view controller.
Click Run → Go. This will compile the application and run it using the iPhone Simulator:
