views:

75

answers:

2

I coding app from iPad and I have to put two separate UITableView in the same screen. For this app I can´t put the UITableView and divid in two sections for requisits reason. It must be two separated. Well, in this case how I can fill the rows of UITableView. Can I have create a DataSource and Delegate in separate classes, one for a first UITableView and other DataSource and Delegate class for the second UITableView or have other approach more elegant?

tks a lot.

+2  A: 

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.

Robot K
Hi Robot K. Not a ugly code, just works :). Doing "union" whith your code and code of user vikingosegundo, this save my day. Tks a lot.
rwvaldivia
A: 

In august I put some example code online where I use 2 different Classes for DataSource and UITableViewDelegate

vikingosegundo
hello vikingosegundo! very good your code example! I download it and solve other problem with you code! again, tks.
rwvaldivia
:) I'm glad, that it was helpful!
vikingosegundo