TheRealRonDez
TheRealRonDez

Reputation: 2807

UISearchbar (UISearchResultsUpdating) with Segue does not dismiss

I have a problem with a UISearchBar. When I search some Text in combination with an UITableView, and ill click on one result Cell, the UISearchBar is still visible in the next UIViewController. the UISearchbar is still there (with the Keyword)

So after ill click on one result, ill get (in the next View Controller)but the searchbar and keyboard is still showing.

how can i dismiss the current UISearchController so that the search bar and keyboard do not show in the next UIViewController?

I have tried:

definesPresentationContext = true

i have tried to dismiss the presentingViewController.

Im doing all of this in the prepared for segue.

My thinking is that I have to dismiss the UISearchController...but how can I access it in preparedForSegue (in the searchResultsViewControllers - this is a tableViewController which is used to present the searchResults)

Upvotes: 4

Views: 592

Answers (2)

Fernando Rocha
Fernando Rocha

Reputation: 2599

You gotta use something like this, forget about the definesPresentationContext

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    searchController.active = false //This will dismiss the searchcontroller, use your own variable for searchController.
    //CALL THE SEGUE YOU WANT BELOW
}

Upvotes: 2

Gjchoza
Gjchoza

Reputation: 187

Try the following code to dismiss the search bar:

[yourSearchController.searchBar resignFirstResponder];

Upvotes: 1

Related Questions