iOS11 中的复杂表格视图部分 - UITableViewAutomaticDimension 问题

screwy tableview sections in iOS11 - UITableViewAutomaticDimension issues

我有一个带有可折叠部分的 tableView。在 iOS 10 或更早版本中,它可以完美运行。在 iOS 11 中,tableView 部分在其他部分中间创建浮动部分 headers 和复制部分 headers,如下所示:

我一直在研究这个问题,其他地方也有报道和讨论here

这是我的 tableView 代码:

class CollapsibleTableViewController: UITableViewController {

    var sections = sectionsData

    override func viewDidLoad() {
        super.viewDidLoad()
        let tableView = UITableView.init(frame: CGRect.zero, style: .grouped)


          // Auto resizing the height of the cell
        tableView.estimatedRowHeight = 44.0
        tableView.rowHeight = UITableViewAutomaticDimension

        self.title = "Education"
                for index in 0 ..< sections.count {
                        sections[index].collapsed = true
                }
    }
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 44.0
}

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 1.0
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension   //making this a fixed value fixes the drawing bug but doesn't let the cells autosize
}

在我上面发布的另一个链接问题中,回复者建议 pre-setting 估计高度如下:

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

这修复了重复的部分,但缩小了我的 tableView 单元格,因此标签字段不再可见,并且单元格不会自动调整大小以显示其中的所有数据。

据报道,iOS 11 通过使用估计值更改了 tableView 高度的工作方式。

我也试过对所有字段使用估计值,如下所示:

tableView.rowHeight = UITableViewAutomaticDimension
tableView.sectionHeaderHeight = UITableViewAutomaticDimension          
tableView.sectionFooterHeight = UITableViewAutomaticDimension

似乎没有任何方法既允许适当地自动调整单元格大小又防止单元格与浮动部分重复 headers。

关于如何解决这个问题有什么想法吗?

viewWillAppear() 中写入您的 tableViews 初始值,然后提供一个 UItableViewAutomaticDimension,如下所示:

tableView.estimatedRowHeight = 75 tableView.rowHeight = UITableViewAutomaticDimension

根据需要对页眉、页脚等进行冲洗和重复