UITableview content size gets wrong while using estimated height

梦想与她 提交于 2020-01-26 04:12:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!