代码之家  ›  专栏  ›  技术社区  ›  Ofir Malachi

设置UITableView单元格高度(包含动态UICollectionView)

  •  0
  • Ofir Malachi  · 技术社区  · 7 年前

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

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

    结果: UITableView'高度FORROW=0

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

    enter image description here

    结果如下所示:

    enter image description here

    所有阅读尝试:

    - (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;
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Ofir Malachi    7 年前

    返回“内容大小” (代替视图.大小)

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