Im trying to UITableAutomaticDimension
for a UITableCell I have. But it doesn't seems to be working
I have tried with this 2 methods.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
tableView.estimatedRowHeight = 250
tableView.rowHeight = UITableViewAutomaticDimension
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
I have also read a lot of stack overflow links that talk about that. Like this one or this one. But none of them worked.
I tried to add this code to my table view to make it work. But it doesn't
NSLayoutConstraint.activate([
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tableView.topAnchor.constraint(equalTo: view.topAnchor),
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
Of course Im reloading the cell and giving 0 lines to the label I have inside.
cell.sizeToFit()
cell.labelTitle.numberOfLines = 0
I also tried to add these 2 lines in the viewDidLoad()
method
tableView.estimatedRowHeight = 250
tableView.rowHeight = UITableViewAutomaticDimension