开发者

(iphone) how to refer multiple tableview

Hi I have a view that contains 2 tableviews.

For a single view I kno开发者_运维百科w 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!


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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜