views:

26

answers:

1

Hi,

I have a ViewController that needs to use 2 UITableViews.
1 is always showing, while the other will show up as a popup after you click on a button on the view.

Typically I set the delegate and datasource to the File's Owner. However, since 1 of the UITableViews is in a popup, I'm not sure how to best tackle this.

e.g how do I tackle this part (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

Please advice.

Thanks,
Tee

+6  A: 

You should have instance variables for both table views declared in your controller:

@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{ 
  UITableView *mainTableView;
  UITableView *popupTableView;
}

In each data source or delegate method, you can check which table view is being passed by the caller:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  if(tableView == mainTableView)
  {
    // Code to create and return a main table view cell
  }
  else if(tableView == popupTableView)
  {
    // Code to create and return a popup table view cell
  }
}
Tim Isganitis
I was just about to type the exact same thing. +1
Joe Ibanez