Reputation: 1286
MY GOAL: Each UITableView Cell Contain 1 UIColletionViewController (dynamic items count)
PROBLEM: UITableView 'HeightForRow's delegate, is call before UIColletionViewController finish load his view + height.
RESULTS: UITableView 'HeightForRow = 0
How can i set the UITableView "HeightForRow" delegate correctly? the UIColletionViewController's content height haven't loaded yet
the result should be like in the following draw:
ALREAD TRY:
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.estimatedRowHeight = 300.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//not working well
return UITableViewAutomaticDimension;
//also tried this:
ResultsTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
Object * object = [_array objectAtIndex:indexPath.section];
[cell setCellObject:object]; //this is build the cell ui
return cell.collection.rect.size.height;
}
Upvotes: 0
Views: 218
Reputation: 1286
return the "content size" (instead of view.size)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//1. get the cell (by identifier)
ResultsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ResultsTableViewCell"];
//2. build cell ui
Object * object = [_array objectAtIndex:indexPath.section];
[cell buildCell:object];
//3. return content size
return cell.collection.collectionView.contentSize.height;
}
Upvotes: 1