Lets say I have a tableview created in the storyboard and referenced as "tableViewJobList" and I want to generate a tableview in each cell of tableViewJobList so I do it in cellForRowAtIndexPath.
My .h file (tableViewJobList delegate and datasource is set to viewcontroller in storyboard)
@interface JobByAccountViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableViewJobList;
...
@end
My .m file
...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//realJoblist is my data array
if (tableView == _tableViewJobList) {
return [realJobList count];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == _tableViewJobList) {
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == _tableViewJobList) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
//each cell has a tableview
UITableView *subTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
subTableView.delegate = self;
subTableView.dataSource = self;
subTableView.frame = CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height);
[cell addSubview:subTableView];
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == _tableViewJobList) {
NSLog(@"outer tableview");
} else {
NSLog(@"inner tableview");
}
...
}
...
In heightForRowAtIndexPath shouldn't the print statement trigger in the else block because those are the tableviews I created programmatically?