First of all, give static height of tableview and take this height outlet. And next step is , you need tableview observe for getting height then assign in this observer you can assign height of each tableview.
override func viewWillAppear(_ animated: Bool) {
Tblvw1.addObserver(self, forKeyPath: "contentSize", options: [.new], context: nil)
Tblvw2.addObserver(self, forKeyPath: "contentSize", options: [.new], context: nil)
Tblvw3.addObserver(self, forKeyPath: "contentSize", options: [.new], context: nil)
Tblvw4.addObserver(self, forKeyPath: "contentSize", options: [.new], context: nil)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
Tblvw1.removeObserver(self, forKeyPath: "contentSize")
Tblvw2.removeObserver(self, forKeyPath: "contentSize")
Tblvw3.removeObserver(self, forKeyPath: "contentSize")
Tblvw4.removeObserver(self, forKeyPath: "contentSize")
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if object is UITableView {
print("contentSize:= \(Tblvw1.contentSize.height)")
self.heightOfTable1.constant = Tblvw1.contentSize.height
self.heightOfTable2.constant = Tblvw2.contentSize.height
self.heightOfTable3.constant = Tblvw3.contentSize.height
self.heightOfTable4.constant = Tblvw4.contentSize.height
}
}
Note: make sure that you must need to disable scroll of all tableview