Set TableView height by the number or rows

前端 未结 9 1758
不思量自难忘°
不思量自难忘° 2021-01-31 10:40

I have got TableView in the MainstoryBoard and the number of rows is random every time. I want the height of the whole TableView to be fl

9条回答
  •  别跟我提以往
    2021-01-31 11:34

    DispatchQueue.main.async {
        var frame = tableView.frame
        frame.size.height = tableView.contentSize.height
        tableView.frame = frame
    }
    

    OR

    DispatchQueue.main.async {
        self.TblViewHeightConstraint.constant = CGFloat((self.array.count) * 30)//Here 30 is my cell height
        self.TblView.reloadData()
    }
    

提交回复
热议问题