iOS 11 的 UITableView 滚动故障(由 reloadData table 和 mopub placer 引起的内容偏移跳跃)

UITableView scroll glitch for iOS 11 (content offset jump caused by reloadData table and mopub placer)

当我升级到iOS 11时,我的应用程序的tableview突然无法平滑滚动。每当我滚动(或reloadData)时,tableview 会突然跳到一个随机的内容偏移位置。

我使用 mopub 的 placer 将广告插入到 tableview 中,我注意到每当应用程序执行时 [tableview reloadData],tableview 滚动偏移会出错并跳到随机位置。

升级到 iOS11 一个月后,我发现了这个讨论: UITableView reload methods show behavior regression 在 Apple 开发者论坛中。

事实证明,这种奇怪的行为是由 [tableview reloadData] 引起的,mopub 广告放置器总是调用 [tableview reloadData]。所以带有mopub ad placer的tableview最容易出现这个问题

解决问题只需设置:

self.tableView.estimatedRowHeight = 0; self.tableView.estimatedSectionHeaderHeight = 0; self.tableView.estimatedSectionFooterHeight = 0;

并且所有滚动和重新加载数据行为都将像 iOS 10.

一样非常流畅