我知道如何在UITableView中使UITableViewCells自我调整大小。问题是如何只有一个特定的细胞自身大小。我的表中有四个不同的自定义UITableView单元格,我想自己只制作一个自定义单元格。
答案 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
}