iOS: Dynamically set UITableView height in Swift

前端 未结 2 1809
孤街浪徒
孤街浪徒 2020-12-29 08:27

Our UITableView exists on a ViewController (and not a TableViewController). We populate it at run time with two rows. When we set a height constraint the table appears fin

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 09:06

    We don't have automatic dimension for UITableView, they only affect the UITableViewCell height. If you want to set the table view height dynamically, I think the best way is to set the table view height constraint equal to its content size after the table view done loading. I mean something like,

    tableViewHeightConstraint.constant = tableView.contentSize.height
    

提交回复
热议问题