0

我的目标: 每个 UITableView 单元格包含 1 个 UIColletionViewController (动态项目计数

问题: UITableView 'HeightForRow 的委托,在 UIColletionViewController 完成加载他的视图 + 高度之前调用。

结果: UITableView 'HeightForRow = 0

如何正确设置 UITableView“HeightForRow”委托? UIColletionViewController 的内容高度尚未加载

在此处输入图像描述

结果应该如下图所示:

在此处输入图像描述

已经尝试:

- (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;
}
4

1 回答 1

1

返回“内容大小”(而不是 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;
}
于 2018-06-24T13:14:52.697 回答