ios - 导航栏中的 UISearchController

标签 ios swift uisearchcontroller

我正在尝试在我的 tableViewController 中使用新的 UISearchController。

但是,当我像使用旧的 searchDisplayController 那样按下 searchBar 时,它如何在 navigationController 中向上移动,我有点困惑?

目前它只是停留在表头中。

这是我的代码:

    self.teamSearchController = ({
        let controller = UISearchController(searchResultsController: nil)

        controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
       controller.searchBar.showsScopeBar = true
        self.tableView.tableHeaderView = controller.searchBar

        return controller
    })()

Controller :

enter image description here

当我点击搜索栏时:

enter image description here

最佳答案

可以将UISearchControllerUISearchBar放在导航栏中,而不是放在表头

self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;

// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;

self.definesPresentationContext = YES;

关于ios - 导航栏中的 UISearchController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29922691/

相关文章:

ios - Xcode:使用新产品名称更新项目产品组

ios - 调用方法时属性访问导致未使用错误

iOS 应用程序测试本地化翻译是否具有相同的键

swift - UISearchController 中的取消按钮在 iOS 13 中没有正确消失

ios - 自定义 navigationItem 的 searchController,但不适用于 iOS 11

ios - UIBarButtonItem 按下时什么都不做

swift - 如何在 UINavigationController 中禁用边缘滑动的过渡动画?

ios - 如何在 UIPageViewController 中预加载 View Controller ?滑动延迟

ios - 为什么我的 SearchController 没有为第一个单元格显示正确的单元格原型(prototype)?

ios - 什么时候释放自动释放对象?