iPad – More than one UITableView in the same screen

You can do this a few different ways. The most straightforward is to use separate classes to handle the datasource and delegate protocols for each table view.

Alternatively, you could use a single class as the datasource and delegate for both, and check the identity of the tableview that’s passed into the protocol methods.

It would looks something like this: (I’m assuming this code is on your view controller.)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat height = 44.0; // default height
    if (tableView == self.myLeftTableView) {
        height = // Compute the cell height for the left table view.
    } else {
        height = // Compute the cell height for the right table view.
    }
    return height;
}

This could get ugly quickly, which is why I’d recommend the first approach.

Leave a Comment