简体   繁体   中英

Blank space between SearchBar and NavigationBar - Swift

I have a simple tableViewController , a searchBar with scopes and a navigationBar .

When I click on my searchBar I see my scopes and all works. Then I click on a row and I go to my DetailPage and the search bar isn't hidden (I don't know why).

So I click cancel and then I return to my tableView . When I return to my tableView there is a blank space between my SearchBar and my NavigationBar .

空格处

This is my code:

      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)
    }

try to Add

  self.automaticallyAdjustsScrollViewInsets = false;

  self.extendedLayoutIncludesOpaqueBars = true

in viewDidload .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM