O'Reilly logo

Learning iPhone Programming by Alasdair Allan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Table View

With refactoring out of the way, now it’s time to put the UI together.

Double-click the RootController.xib file in Xcode to open it in Interface Builder. Then double-click on the View icon in the RootController.xib window to bring up the View window, and drag a table view from the Library window into the view. You’ll find the table view under Cocoa TouchData Views in the Library window.

Center the UITableView in the view, as shown in Figure 5-4. You must confirm that you’ve dropped it as a subview of the main view by clicking the View Mode widget on the menu bar of the RootController.xib window and choosing List View. It should look as shown in Figure 5-4, with Table View appearing under View. Save the .xib file using ⌘-S.

Dragging a UITableView from the Library window into the UIView

Figure 5-4. Dragging a UITableView from the Library window into the UIView

Switch back to Xcode to add the outlets and delegates Interface Builder needs so that you can connect the UITableView to your code. Open the RootController.h interface file and add a UITableView variable to the @interface declaration, then declare this as a property and an IBOutlet. You also need to declare that this class implements both the UITableViewDataSource and the UITableViewDelegate protocols. This means that it both provides the data to populate the table view and handles events generated by user interaction with the table view.

Once you’ve done this, the RootController.h ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required