使用估计高度时 UITableview 内容大小出错 [英] UITableview content size gets wrong while using estimated height

查看:28
本文介绍了使用估计高度时 UITableview 内容大小出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用表格视图内容大小时出现空白空间.我提到这个像https://forums.developer.apple.com/thread/81895.但它对我不起作用.当我打电话来获取表格内容大小时,它给出了错误的大小,例如,如果表格视图内容大小是 100 意味着它给我 140 或 80 像......等.所以,如果有人知道如何处理或如何获得正确的表格视图内容大小??

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 ??

推荐答案

使用下面的代码一次

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)
        }
    }
}

这篇关于使用估计高度时 UITableview 内容大小出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆