美文网首页
解決 iOS 11 下 UITableView 的 conten

解決 iOS 11 下 UITableView 的 conten

作者: Kevin追梦先生 | 来源:发表于2018-07-02 11:20 被阅读42次

使用 iOS 11 測試時,發現 UITableView 的 contentSize 與 contentOffset 無法取得準確的值,導致某一些使用到這些屬性 (例如將表格捲動到指定的高度) 的功能出錯。

這其實是因為 iOS 11 預設會開啟表格的 Self-Sizing。當開啟了這個屬性以後,得到的表格 contentSize 只會是暫時的估算值,等於 estimatedRowHeight 乘上 cell 個數,而不會立即得到正確的 contentSize。當我們有功能去使用到這個值時就會發現和預期的效果不同。

解決方式是將表格的以下三個屬性設成 0,這樣就可以關閉 Self-Sizing 了

_tableView.estimatedRowHeight = 0;

_tableView.estimatedSectionHeaderHeight = 0;

_tableView.estimatedSectionFooterHeight = 0;

Reference:

https://forums.developer.apple.com/thread/81895

http://wetest.qq.com/lab/view/326.html

相关文章

网友评论

      本文标题:解決 iOS 11 下 UITableView 的 conten

      本文链接:https://www.haomeiwen.com/subject/kockuxtx.html