0

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

enter image description here

the result should be like in the following draw:

enter image description here

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;
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Ofir Malachi
  • 1,145
  • 14
  • 20

1 Answers1

1

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;
}
Ofir Malachi
  • 1,145
  • 14
  • 20