ios - UITableViewController隐藏导航栏[搜索栏]

标签 ios swift uisearchbar

我已将搜索栏添加到导航栏标题 View 中,当我开始搜索 UITableViewController 隐藏导航栏时,如何在导航栏下方获取 UITableViewController。

Before Searching

Before Searching

After Typing

After Typing

Code

        let resultController = mainStoryboard.instantiateViewControllerWithIdentifier("SearchTableViewController") as! UITableViewController

        self.searchController = UISearchController(searchResultsController: resultController)
//        self.searchController.searchResultsUpdater = self
//        self.searchController.delegate = self
//        self.searchController.searchBar.delegate = self
        self.searchController.searchBar.tintColor = UIColor.whiteColor()
        self.searchController.searchBar.placeholder = "Search Outlets"
        self.searchController.dimsBackgroundDuringPresentation = false
        self.searchController.hidesNavigationBarDuringPresentation = false

最佳答案

据我所知,您的 View Controller 没有设置 definesPresentationContext 属性。如果不设置这个,必然会发生奇怪的事情。尝试像这样更新您的代码:

let resultController = mainStoryboard.instantiateViewControllerWithIdentifier("SearchTableViewController") as! UITableViewController

self.searchController = UISearchController(searchResultsController: resultController)
//self.searchController.searchResultsUpdater = self
//self.searchController.delegate = self
//self.searchController.searchBar.delegate = self
self.searchController.searchBar.tintColor = UIColor.whiteColor()
self.searchController.searchBar.placeholder = "Search Outlets"
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.hidesNavigationBarDuringPresentation = false

self.definesPresentationContext = true

最后一行是我添加的行。当我在自己的应用程序中测试这一点时,未指定这一行导致了您所看到的行为。

关于ios - UITableViewController隐藏导航栏[搜索栏],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38955822/

相关文章:

ios - Swift 3 - 为每个设备设置 X-Y 轴 UILabel

ios - 如何使 UIView 匹配 UILabel 的大小

swift - webViewDidStartLoad 和 webViewDidFinishLoad 不工作

ios - 如何以编程方式快速设置物理定义?

swift - 为什么要创建 "Implicitly Unwrapped Optionals",因为这意味着您知道有一个值?

iphone - 如何显示登录和关闭设置 - Storyboard

ios - 使用 API 响应 Swift 填充表

ios - UIView 宽度在第一次启动时显示不同

swift - Swift 中 UIPickerView 顶部的搜索栏

ios - UISearchBar 关闭动画问题