iOS 11 UITableView 错误

iOS 11 UITableView bug

可以使用 repo here.

重现该错误

我的 UITableView 中 iOS 11 中有一个奇怪的错误影响了我的项目。 有问题的 TableView 已分组,具有可扩展的单元格。

我的 iOS 10 分支上没有出现许多奇怪的效果:

  1. 标题叠加
  2. 当单元格折叠时内容大小超过 UITableView 容器大小时出现奇怪的传送问题
  3. 当内容大小超过容器大小时,在滚动开始时奇怪地传送到 tableview 的顶部
  4. 单元格大小错误(经常)

在 Apple Developers 论坛上还有一张似乎相关的工单 here

我试了没有成功:

if #available(iOS 11.0, *) {
    tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
}

我正在尝试查找 iOS 11 中可能导致此问题的更改行为。

如有任何帮助,我们将不胜感激!

编辑:剪裁到边界有帮助(但最终,它 hides/clips 问题)。我还有一些问题(2、3 和 4)。 当我尝试打开一个单元格时,它会传送回顶部而不是顺利进行。 当我打开一个单元格并想顺利地滚动到它时,它会传送到顶部然后只滚动到它。 (必须添加一个额外的部分来显示)。

这是问题的视频(使用iPhone 7 Plus,iOS 11,Xcode 9 Golden Master):https://youtu.be/XfxcmmPdeoU

在 iOS 11 中,所有估计的 UITableView 属性(estimatedRowHeightestimatedSectionHeaderHeightestimatedSectionFooterHeight)默认为 UITableViewAutomaticDimension

我看到你的细胞很好,因为你在 heightForRow 中返回 UITableViewAutomaticDimension。但是,对于您的节页眉和页脚,您没有使用自动调整大小。我会尝试通过将 estimatedSectionHeaderHeightestimatedSectionFooterHeight 设置为 0.

来禁用 headers/footers 中的所有自动调整大小行为

来源:iOS 11 Floating TableView Header

试试这个解决方法,假设您的 IBOutlets 和变量在 StandardHeaderView.swift 中不是私有的:

    func toggleSection(section: SectionType) {
    self.sectionsOpened[section] = !self.sectionsOpened[section]!

    let sectionIndex = self.sections.index(of: section)!

    let indexPath = IndexPath(row: 0, section: sectionIndex)

    UIView.animate(withDuration: 0.25) {
        self.tableView.reloadRows(at: [indexPath], with: .automatic)
        if let headerView = self.tableView.headerView(forSection: sectionIndex) as? StandardHeaderView {
            headerView.configWith(title: headerView.headerTitleLabel.text!, isOpen: self.sectionsOpened[section]!, selector: headerView.selector)
        }

        self.tableView.scrollToRow(at: IndexPath(row: 0, section: sectionIndex), at: .top, animated: true)
    }
}