我正在尝试使用 UISearchController 为我的 iPhone 应用程序显示一个简单的搜索屏幕。 我使用了一个 UITableViewController 和一个嵌入到 UINavigationController
中的 UISearchController- 这让我看到以下屏幕(状态 1)
- 当用户点击搜索字段时,我会看到以下屏幕(状态 2): 搜索栏很好地显示在状态栏下方的屏幕顶部。
我想做的是直接进入状态2,而不是进入状态1
我尝试添加这段代码
presentViewController(searchController, animated: true, completion: nil)
但如果 animated 为 false,它要么不显示搜索栏,要么按我的意愿显示它,但在经过不必要的过渡后暂时显示导航栏
最佳答案
好的,我刚刚找到如何阅读这个答案 UISearchController in a UIViewController
我只需要像这样添加搜索栏就可以得到想要的效果
searchController.hidesNavigationBarDuringPresentation = false
// tableView.tableHeaderView = searchController.searchBar
navigationItem.titleView = searchController.searchBar
关于IOS8 UISearchController 直接显示搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27867611/