UISearchBar 使 UITableView 中的单元格内容与部分发生冲突

UISearchBar colliding cell contents in UITableView with sections

我在 UIViewController 中有一个 UITableView...

我正在使用 UISearchController 给我一个搜索栏并将其设置为 table 的 header 视图。我还在 UITableView 中使用部分。我的问题是,在第一次演示时,table header 与第一个单元格发生碰撞...

搜索栏被激活一次然后关闭后,table 呈现出我期望的样子...

代码代码看起来像...

override func viewDidLoad() {
    super.viewDidLoad()
    self.table.dataSource = self
    self.table.delegate = self
    self.table.tableHeaderView = self.searchController.searchBar

    self.definesPresentationContext = true
    self.searchController.searchBar.sizeToFit()
    self.searchController.dimsBackgroundDuringPresentation = false

    self.searchController.searchResultsUpdater = self
    self.searchController.delegate = self
}

... 这种样式在其他 table 没有部分的情况下效果很好。

对于未来的用户,将 table 行设置为自动高度解决了这个问题...

    self.table.estimatedRowHeight = 44
    self.table.rowHeight = UITableViewAutomaticDimension