I have a View which has two labels and a Table View inside it. I want label 1 to always stay above my Table View and label 2, to be below the Table View. The problem is that
For TableView Height adjustment automatically with its content size use this in ViewController class.
//constraintTableViewHeight :- tableview height constraint
override func viewWillLayoutSubviews() {
super.updateViewConstraints()
self.constraintTableViewHeight.constant = self.tableView.contentSize.height
}
and also add this
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
self.viewWillLayoutSubviews()
}
This code easily adjust tableview height automatically with its content size.