How to get the size of a UITableView's content view?

后端 未结 4 972
无人共我
无人共我 2021-02-01 19:20

I would like to get the size of a UITableView\'s content view when the table is populated. Any suggestions on how to do this?

4条回答
  •  半阙折子戏
    2021-02-01 19:51

    For table views whose heights are dynamically sized by their cells' contents--

    My tableView is contained in a UIView, whose updateConstraints() function looks like this:

    override func updateConstraints() {
        self.tableView.layoutIfNeeded()
        self.tableViewHeight.constant = min(300, self.tableView.contentSize.height)
        super.updateConstraints()
    }
    

    tableViewHeight is an IBOutlet to the XIB-assigned height of the table view. I get whichever is smaller--300 points, or the height of the table view's content size.

提交回复
热议问题