如何为 parent 和 child 创建单独的表格视图单元格高度?

How to create tableview cell height separate for parent and child?

我在 single tableview 中创建了两个不同的 tableviewcell,现在我在 storyboard "row height" 中为单独的 cells 设置了 separate height。现在的问题是每当我 运行 应用程序它没有改变两个高度都相同。

你应该实施

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

和return父子单元格的不同高度。

实施示例:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat height = 0;

    UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    if ([cell.reuseIdentifier isEqualToString:@"ParentCell"]) {
        height = 100.0; //Parent Cell height
    } else if ([cell.reuseIdentifier isEqualToString:@"ChildCell"]) {
        height = 50.0; //Child Cell height
    }

    return height;
}