问题
I am getting empty space while I am using the Table view content size. I referred this like https://forums.developer.apple.com/thread/81895. But it did not work for me. When I call to get the table content size , it gives wrong size for example, if table view content size was 100 means then it gives me 140 or 80 like...etc. So, If anyone knows how to handle OR how to get correct table view content size ??
回答1:
use the below code once
override func viewDidLoad() {
super.viewDidLoad()
yourTableView.addObserver(self, forKeyPath: "contentSize", options: .new, context: nil)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if(keyPath == "contentSize"){
if let newvalue = change?[.newKey] {
let contentHeight: CGFloat = yourTableView.contentSize.height
print(contentHeight)
}
}
}
来源:https://stackoverflow.com/questions/54427633/uitableview-content-size-gets-wrong-while-using-estimated-height