Calculate the table's contentSize.height with custom cells of different types iphone

前端 未结 7 1198
-上瘾入骨i
-上瘾入骨i 2020-12-16 15:03

In my application , the tableview is having different types of custom cells with different heights. I want to put a view below this tableView, for which I need to calculate

7条回答
  •  执念已碎
    2020-12-16 15:37

    This is an old question, but, today I've solved my problem with this

      func viewDidLoad() { 
          super.viewDidLoad()
    
          tableView.rowHeight = UITableViewAutomaticDimension
          tableView.estimatedRowHeight = 44 //  >= 2
        }     
    
      func getTableViewHeight() -> CGFloat{ 
          tableView.reloadData()
          tableView.layoutIfNeeded()
    
          return tableView.contentSize.height + tableView.contentInset.bottom + tableView.contentInset.top
        }
    

提交回复
热议问题