搜索栏和导航栏之间的空白 space - Swift

Blank space between SearchBar and NavigationBar - Swift

我有一个简单的 tableViewController、一个带范围的 searchBar 和一个 navigationBar

当我点击我的 searchBar 时,我会看到我的示波器和所有作品。然后我单击一行并转到我的 DetailPage 并且搜索栏没有隐藏(我不知道为什么)。

所以我点击取消然后我return到我的tableView。当我 return 到我的 tableView 时,我的 SearchBar 和我的 NavigationBar 之间有一个空白 space。

这是我的代码:

      self.resultSearchController = ({
            let controller = UISearchController(searchResultsController: nil)
            controller.searchResultsUpdater = self
            controller.hidesNavigationBarDuringPresentation = true
            controller.dimsBackgroundDuringPresentation = false
            controller.searchBar.sizeToFit()
            controller.searchBar.scopeButtonTitles = ["Title", "Author", "Location", "Price", "User"]
            self.tableView.tableHeaderView = controller.searchBar
            return controller
        })()

 func updateSearchResults(for searchController: UISearchController)
    {
        let scopes = resultSearchController.searchBar.scopeButtonTitles
        let currentScope = scopes![resultSearchController.searchBar.selectedScopeButtonIndex] as String
        filterContentForSearchText(searchText: searchController.searchBar.text!, scope: currentScope)
    }

尝试添加

  self.automaticallyAdjustsScrollViewInsets = false;

  self.extendedLayoutIncludesOpaqueBars = true

viewDidload.