UISearchController search bar overlap first cell when active

前端 未结 7 2485
慢半拍i
慢半拍i 2020-12-21 08:52

I am using UISearchController to search for data in my tableview. I am not using table view controller. I would like to hide the navigation bar when my search b

7条回答
  •  悲&欢浪女
    2020-12-21 09:51

    Reseting tableView.tableHeaderView = searchController.searchBar after the dismissing searchController solved the issue for me.

      public func didDismissSearchController(_ searchController: UISearchController) {
                tableView.tableHeaderView = searchController.searchBar
    }
    

    Unfortunately didDismissSearchController doesn't get called if you select a result and go back to parent viewController. In this case you need reset the searchBar.frame back to origin position:

    if let frame = tableView.tableHeaderView?.frame {
        searchController.searchBar.frame = frame
    }
    

提交回复
热议问题