chapter thirteen

Formatting Table Cells

The Structure of the master view controller combines UITableViewController as well as the two protocols that it adopts (UITableViewDelegate and UITableViewDataSource) so that MasterViewController can become the delegate and the data source of your UITableView. You’ve seen that structure in Chapter 12, “Exploring the Table View in the Template,” and now it’s time to delve into a number of the methods that make up this combined object.

A large number of the methods—particularly in the adopted protocols—are self-explanatory both in their names and their implementations. For example, here’s the method that controls re-ordering table rows:

- (BOOL)tableView:(UITableView *)tableView

    canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    // The table view should not be re-orderable.

    return NO;

}

The comment is part of the Master-Detail Application template, as are comments in many of the other basic protocol implementations in the template. The only thing that might be a little perplexing to you is the mechanics of breaking down the NSIndexPath into a row and section, but even that isn’t an issue in many cases (and it’s explained at the end of this chapter in the “Configuring the Detail Item” section.) This method is called as needed for each row in the table. Most of the time you want all rows to be re-orderable or for none of them to be re-orderable. Don’t worry about the value of indexPath—just set the return value to NO or YES and, ...

Get iOS 6 Foundations now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.