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

后端 未结 4 928
无人共我
无人共我 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 20:07

    I don't know how much people will like this answer because I am not sure that I like it. But I managed to get something working with this.

    This will work for dynamic height cells. The callback will get called a few times as the tableview figures out its contentView

    class ContentSizeNotifyingTableView: UITableView {
        var contentSizeDidChange: ((CGSize) -> ())?
    
        override var contentSize: CGSize {
            didSet {
              self.contentSizeDidChange?(self.contentSize)
            }
        }
    }
    

提交回复
热议问题