简体   繁体   English

SearchBar和NavigationBar之间的空白-Swift

[英]Blank space between SearchBar and NavigationBar - Swift

I have a simple tableViewController , a searchBar with scopes and a navigationBar . 我有一个简单的tableViewController ,一个带作用域的searchBar和一个navigationBar

When I click on my searchBar I see my scopes and all works. 当我单击searchBar我会看到我的范围和所有作品。 Then I click on a row and I go to my DetailPage and the search bar isn't hidden (I don't know why). 然后我单击一行,然后转到我的DetailPage ,搜索栏没有隐藏(我不知道为什么)。

So I click cancel and then I return to my tableView . 因此,我单击取消 ,然后返回到tableView When I return to my tableView there is a blank space between my SearchBar and my NavigationBar . 当我返回tableView时,我的SearchBarNavigationBar之间有一个空格。

空格处

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 . viewDidload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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