在viewWillLayoutSubview中没有获得正确的TableView ContentSizeHeight

问题描述

我有自定义tableviewClass

  class CustomTableviewController UITableView,UITableViewDelegate,UITableViewDataSource{
}

我在该类中还有另一个UIViewController类,可不时加载数据

    class MyViewController:UIViewController {
    @IBOutlet weak var tableView: CustomTableviewController!
override func viewWillLayoutSubviews() {
        
        let height = tableView.contentSize.height + tableView.contentInset.bottom + tableView.contentInset.top + actionContainerHeight + navigationView.frame.height + textField.frame.height + 44
        heightEventDelegate?.getReviewContentHeight(height: height)
        super.viewWillLayoutSubviews()
    }
    }

在MyViewController中,我有时会更改数据,因此我需要获取tableview的contentsize.height。

然后我将此MyViewController添加到ParentViewControllers内部的ScrollView中。并且不需要在scrollview中滚动此tableview。所以我得到tableview的contentSize并将其设置为scrollview。

但是问题是无法正确获取tableview contentsize。它只是第一次在 viewWillLayoutSubviews 方法内部命中。

任何人都有获取正确的contentSize的想法。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)