O'Reilly logo

iOS 6 Foundations by Jesse Feiler

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

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, ...

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