Reputation: 1176
I am having the problem in setting the dynamic height for my table view cell.I have used the following code to set it, but it's not working in fact now the cell height has even increased.
See this the code I have added in my project:
override func viewDidLoad() {
super.viewDidLoad()
tableview.rowHeight = UITableViewAutomaticDimension
print(tableview.rowHeight)
tableview.estimatedRowHeight = 120
}
This the screenshot for the constraints of the table view cell contents:
Please have a look at the constraints as well. Thanks in advance :)
Upvotes: 0
Views: 108
Reputation: 2096
If u have done everything correct and still u r unable the get desired output means the issue will be with constraints.
I have made a simple constraint layout, use this skeleton as reference and re-constraint your cell.
Add (W:20, H:20) to [img].
Make sure you have set number of lines to 0, and all other automatic dimension stuff's.
IB Constraint Screenshot.
Upvotes: 1
Reputation: 518
You may consider using func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
. It's a method in the UITableViewDelegate and you can use it to return a specific height for the rows you want.
https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614998-tableview
This link may help: Dynamic tableViewCell height
Upvotes: 0