IOS8 UISearchController displays search bar directly
I am trying to show a simple search screen for my iphone app using UISearchController. I used UITableViewController and UISearchController which I have embedded in UINavigationController
- This will give me the following screen ( state 1 )
- When user clicks on the search box, I get the screen below ( state 2 ): The search bar displays well at the top of the screen below the status bar.
What I want to do is to get state 2 immediately without going to state 1
I tried to add this code
presentViewController(searchController, animated: true, completion: nil)
but it either doesn't display the search bar if the animated is false, or it displays it the way I want but after an unnecessary transition that temporarily displays the navbar
+3
source to share
1 answer
Ok, I just found how to do it by reading this answer UISearchController in UIViewController
I just need to add a search bar to get the desired effect
searchController.hidesNavigationBarDuringPresentation = false
// tableView.tableHeaderView = searchController.searchBar
navigationItem.titleView = searchController.searchBar
+6
source to share