0

How to set Tableview height dynamically like in android. i tried with following code, but its not working.

 tblHeightConstraint.constant = downSelectionTbl.contentSize.height

see this below link i tired upvote answers even though its not resolved my issue.

iOS: Dynamically set UITableView height in Swift

Ram
  • 810
  • 1
  • 13
  • 19

1 Answers1

9

Do like this,

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    tblHeightConstraint.constant = downSelectionTbl.contentSize.height
}
Venk
  • 5,929
  • 9
  • 38
  • 50
  • @ram for alternate solution check this ans: https://stackoverflow.com/questions/2595118/resizing-uitableview-to-fit-content/48623673#48623673 – Venk Mar 01 '18 at 13:12
  • func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell this function working like a charm.. Thq @venkat – Ram Mar 02 '18 at 04:26