here is a storyboard image. i have take a dynamic tableviewcell 我尝试过拖放UITableViewCell
并从故事板中更改行高,它无法在运行时扩展单元格高度。
在Xcode 9.0.1
和Swift 4
中,我面临的问题是细胞高度在运行时没有增加。所以,请帮我解决这个问题。
答案 0 :(得分:6)
设置行高的自动尺寸&估计行高,确保执行以下步骤,自动尺寸对单元格/行高度布局有效。
UITableViewAutomaticDimension
分配给rowHeight& estimatedRowHeight heightForRowAt
并向其返回值UITableViewAutomaticDimension
)-
@IBOutlet weak var table: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Don't forget to set dataSource and delegate for table
table.dataSource = self
table.delegate = self
// Set automatic dimensions for row height
table.rowHeight = UITableViewAutomaticDimension
table.estimatedRowHeight = UITableViewAutomaticDimension
}
// UITableViewAutomaticDimension calculates height of label contents/text
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
用于UITableviewCell中的标签实例
答案 1 :(得分:2)
试试这个:
1。实施UITableViewDelegate
方法:
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat
{
return 200
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return UITableViewAutomaticDimension
}
2。将适当的constraints
应用到UITableViewCell
,以便它可以正确计算自己的height
。必须出现右UITableViewCell
UI。 autolayout
中的任何问题都可能导致您的单元格UI以意外的方式运行。