【发布时间】:2020-11-27 11:59:51
【问题描述】:
我查看了很多示例,但不知何故它们不起作用。 我的代码如下。 自定义单元格中的对象约束:
下面是类中的代码:
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
view.addSubview(tableView)
tableView.separatorStyle = .none
tableView.estimatedRowHeight = 200
}
//表格视图->
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 340
}
【问题讨论】:
-
什么问题?
-
在 heightForRowAt 中设置高度,即单元格的设置高度。
-
请将您的代码添加为代码而不是图像
-
嗨,萨加尔!我想创建一个动态单元格。单元格的高度应根据标签中文本的数量而变化。
标签: swift uitableview autolayout heightforrowatindexpath