3
votes

I am trying to display a simple search screen for my iphone app using a UISearchController. I used a UITableViewController and a UISearchController that I embedded inside a UINavigationController

  • This get me the following screen (state 1)

searchcontroller with navigation bar

  • When user click on the search field I get the screen below (state 2): The search bar display nicely at the top of the screen below the status bar.

searchcontroller activated

What I want to do is to get state 2 straight away without going to state 1

I tried to add this code

presentViewController(searchController, animated: true, completion: nil)

but it either does not show the searchbar if animated is false or display it as I want but after an unnecessary transition that temporaryly shows the navigation bar

1
You question makes no sense. You are the one who put the search field as the header view of the table view to begin with (state 1). If that is not what you wanted, why did you do it? If you wanted the search field to live in the navigation bar, why didn't you put it in the navigation bar instead?matt

1 Answers

7
votes

Ok I just found how to do it reading this answer UISearchController in a UIViewController

I just need to add the searchbar like this to get the desired effect

    searchController.hidesNavigationBarDuringPresentation = false
    // tableView.tableHeaderView = searchController.searchBar
    navigationItem.titleView = searchController.searchBar