2
votes

Hi I have a view that contains 2 tableviews.

For a single view I know this delegate method can help me fill content of each row

  • (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

But since I have 2 tableviews, how can I refer to each of them and fill content separately?

Thanks for helping!

4
If you having data for display in other way then please explain hows you show data in table view.(If way is different from my answer).Ishu
Hi thanks for your help. I need to show my data in two table at the same time and just wondered how to refer to each of them when (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath is called. Toastor answered my question well.Yongzhi
possible Duplicate Question stackoverflow.com/a/11448126/846372Soniya

4 Answers

3
votes

The "current" tableview will pass a pointer to itself along as an argument when calling its delegate's methods like the one you mentioned.

So, all you need to do is to compare the pointer (tableView) to references of the two tableviews that you stored or added as property previously.

Proceed like so within your delegate methods:

if (tableView == myFirstTableView) {
   //code to handle first tableview
} else if (tableView == mySecondTableView) {
   //code to handle second tableview
}

Edit: Both tableviews need to share the same delegate for this to work, which would make sense anyway since they appear on the same view.

1
votes

since you have two table view so you need implement proper if else condition where you need which table view is going to display.Ok Make IBOutlet for both table.

then now in viewWillAppear

make datasource for the display(Array of data) and

if(...) { firstTable.hidden=NO; secondTable.hiden=YES; [firstTable reloadData]; } else { secondTable.hidden=NO; firstTable.hidden=YES; [[secondTable reloadData];

}

Now dont worry with every condition you would not require any condition in CellForRowAtIndexPath or didSelectRowAtIndexPath.

0
votes

Further to Toastor's answer above, you may of course set different delegates and data sources for each table, although most often it is simpler to use the same delegate/data source for all NSTableViews in the same view.

0
votes

I prefer to use property tag for distinguishing the desired UIView. The UITableView is a subclass of UIView, so it have this property too.