Reputation: 191
I would like to display 2 UItableView
on a same UIView
. Important thing: when I select a row on the first table (master
), I want to display the detail rows on the second table (detail
).
In order to do that, I have :
UIViewController
with 2 UITableView
IB Outlet properties, linked with the 2 tables in the storyboardUITableView
in the root UIViewController
UITableViewController
for each UITableView
I manage to display data in the first table, but not in the second, although the tableView:numberOfRowsInSection:
is correct for the two tables.
When I run my app in debug mode, I don't see any call to the tableView:cellForRowAtIndexPath:
method for the detail table.
I don't understand what I have missed or where I'm wrong. Anyone could help me ?
Here are parts of my code :
@interface RootViewController : UIViewController
{
MasterTVController * masterController;
IBOutlet UITableView * masterTV;
IBOutlet UITableView * detailTV;
}
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (masterController == nil) {
masterController = [[masterTVController alloc] init];
}
[masterTV setDataSource:masterController];
[masterTV setDelegate:masterController];
masterController.view = masterController.tableView;
[detailTV setDataSource:masterController.detailTVController];
[detailTV setDelegate:masterController.detailTVController];
}
@interface MasterTVController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
{
NSMutableArray * masterArray;
NSMutableArray * detailArray;
DetailTVController * detailTVController;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
self.detailTVController = [[DetailTVController alloc] init];
self.detailTVController.view = self.detailTVController.tableView;
}
return self;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.detailArray = [[self.masterArray objectAtIndex:indexPath.row] objectForKey:@"details"];
self.detailTVController.dataArray = detailArray;
[self.detailTVController.tableView reloadData];
}
Upvotes: 0
Views: 930
Reputation: 385500
I suspect your detailTVController.tableView
is not set to detailTV
, so that last line in tableView:didSelectRowAtIndexPath:
is not sending reloadData
to the right table view. Try adding this in viewDidLoad
:
masterController.detailTVController.tableView = detailTV;
You might also need to set masterController.tableView
in a similar fashion.
Also, one of these two lines seems suspicious:
[menusTV setDataSource:masterController];
[masterTV setDelegate:masterController];
Upvotes: 1