“大小检查器”中的Tableview行高是覆盖行高数据源的单元格

时间:2017-09-11 09:13:43

标签: swift uitableview

我有一个代码,用于定义每个表视图单元格的行高。但是,Size Inspector中定义的行高会覆盖所有内容。我该怎么办?

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.row == 0 {
        return CGFloat(81.0)
    } else if indexPath.row == 1 {
        return CGFloat(212.0)
    } else if indexPath.row == 2 {
        return CGFloat(127.0)
    } else if indexPath.row == 3 {
        return CGFloat(147.0)
    } else if indexPath.row == 4 {
        return CGFloat(63.0)
    }
    return 0
}

1 个答案:

答案 0 :(得分:0)

看起来您将estimatedRowHeights设置为实际的行高。

你想写:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    switch indexPath.row {
    case 0:
        return CGFloat(81.0)
    case 1:
        return CGFloat(212.0)
    case 2:
        return CGFloat(127.0)
    case 3:
        return CGFloat(147.0)
    case 4;
        return CGFloat(63.0)
    default:
        return 0
    }
}

不是estimatedHeight...

相关问题