I have a ViewController that needs to use 2 UITableViews
.
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.
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
}
}
精彩评论