3

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
    Jan 9, 2015 at 19:20

1 Answer 1

7

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
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.