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

标签 ios swift uitableview uisearchbar uisearchcontroller

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

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

所以我单击取消,然后返回到我的tableView。当我返回到我的 tableView 时,我的 SearchBar 和我的 NavigationBar 之间有一个空白区域。

Blank 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 中。

关于ios - 搜索栏和导航栏之间的空白 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39718958/

相关文章:

ios - 如何将红色圆形减号图标作为透明背景的png?

ios - 如何在 Swift 5 中的 UIScrollView 内以编程方式生成的 UIView 上实现点击手势

ios - 在 Swift/iOS 中从 UITableView 删除行并从 NSUserDefaults 更新数组的正确方法

ios - 如何使用动态内容

ios - RestKit session 管理

ios - UIPageviewController 使用 Storyboard 崩溃

ios - 点击时禁用 UICollectionViewCell,并随机化单元格

ios - 尽管相机和节点共享原点,但 SceneKit 相机旋转错误

iphone - iOS : UITableView reloadData not working

ios - 连接到 Google Drive API 时出错(Swift 5)