Question : table view content size not return correctly
Answered by : tayyab-mubeen
override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.instructiontableview.addObserver(self, forKeyPath: "contentSize", options: .new, context: nil)
}
override func viewWillDisappear(_ animated: Bool) { self.instructiontableview.removeObserver(self, forKeyPath: "contentSize") super.viewWillDisappear(true)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?){ if(keyPath == "contentSize"){ if let newvalue = change?[.newKey]{ let newsize = newvalue as! CGSize self.heightofinstructioncontainerview.constant = newsize.height } }
}
Source : https://stackoverflow.com/questions/42693072/uitableview-content-size-is-not-returning-correctly-swift | Last Update : Thu, 12 May 22