我在 ScrollView 中有一個 TableView。我為動態單元格和表格視圖的動態高度設定了一些約束和自動布局。但是我對每個單元格都有一些問題,每個單元格中的一些并沒有顯示所有內容。任何身體幫助?

并在資訊標簽右側自動布局數字

表格視圖代碼
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCell.identifier, for: indexPath) as! TableViewCell
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
動態表格視圖的代碼
override func updateViewConstraints() {
tableHeightConstraint.constant = tableView.contentSize.height
super.updateViewConstraints()
}
我現在的問題:

我被困了幾天。非常感謝。
uj5u.com熱心網友回復:
您可以在這里做的事情很少。
- 嘗試將文本標簽的底部約束設定為“大于或等于”。
layoutIfNeeded()設定 tableView 高度約束后呼叫
uj5u.com熱心網友回復:
在 viewDidLoad 中添加這 2 行
tableView.estimatedRowHeight = 68.0
tableView.rowHeight = UITableViewAutomaticDimension
檢查這個例子以及約束
https://github.com/iDhaval/TableCellDynamicHeight
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/421124.html
標籤:
