我有一个表格 View 。我想要一些具有动态高度的 tableview 单元格,而其他具有固定高度的单元格。对于动态高度,我在 viewDidLoad View Controller 委托(delegate)中使用了以下几行。
tableView.estimatedRowHeight = 200
tableView.rowHeight = UITableViewAutomaticDimension
在一个表格 View 中使用固定高度的单元格和自动调整单元格的有效方法是什么?
提前致谢。
最佳答案
swift 3
通过执行此操作,您可以在表格 View 中重新运行动态和静态单元格高度
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 {
return 120.0 // for static cell height
}
else {
return UITableViewAutomaticDimension // for dynamic cell height
}
}
你必须像那样实现另一个 tableview estimatedHeightForRowAt 方法
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 {
return 120.0
}
else {
return UITableViewAutomaticDimension
}
}
不要忘记将标签 lineNumbers 设置为 0 和 lineBreakMode,标签将动态扩展,最重要的是不要将标签高度设置为固定。
关于ios - 一些具有动态高度的表格 View 单元格,其他具有固定高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47443494/