ios - 使用估计高度时 UITableview 内容大小出错
问题描述
我在使用Table view content size时得到了空白空间。我将其称为https://forums.developer.apple.com/thread/81895。但这对我不起作用。当我调用获取表格内容大小时,它给出了错误的大小,例如,如果表格视图内容大小为 100 意味着它给了我 140 或 80 之类的......等等。那么,如果有人知道如何处理或如何获得正确的表格视图内容大小?
解决方案
使用以下代码一次
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)
}
}
}
推荐阅读
- firebase - TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) at Function.all (
) Firebase 云功能 - flutter - 颤动:隐藏文本字段的键盘
- python - 如何将 zappa 应用程序部署到 https://www.my_domain.com 和 https://my_domain.com
- javascript - DOMContentLoaded 不会在 IOS Safari 上触发
- java - 有人可以解释这两个简单的循环吗?
- python - 比较python中的两个数组以查看它们是否共享任何值
- typescript - 如何使用 map 运算符将新字段添加到对象中,并将其添加到返回到 Observable 的数组中?
- ant - 如何通过命令行选项将命令行选项传递给 java 编译器
蚂蚁任务使用 ? - git - 来自 Windows 10 主机的 Centos 7 devcontainer 中的 GPG 签名提交
- jquery - 固定页眉出现在不同页面的不同位置