自定义特定的UITableView Cell

时间:2017-09-17 18:24:39

标签: swift uitableview autolayout contentsize

我知道如何在UITableView中使UITableViewCells自我调整大小。问题是如何只有一个特定的细胞自身大小。我的表中有四个不同的自定义UITableView单元格,我想自己只制作一个自定义单元格。

2 个答案:

答案 0 :(得分:1)

您可以根据

检查返回dinamicHeigth所需的单元格以及func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat返回UITableViewAutomaticDimension

使用第0行作为条件的示例代码

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

        if(indexPath.row == 0)
        {
            return UITableViewAutomaticDimension
        }

        return 88
    }

答案 1 :(得分:1)

您必须知道要为UITableViewAutomaticDimension实现哪些行,因为当调用heightForRowAt时,尚未创建任何单元格,因此您无法检查单元格类型为什么你需要检查indexPath.row

例如:

switch indexPath.row {
case 0:
    return 100
case 1,2,3:
    return UITableViewAutomaticDimension
default:
    return 100
}