views:

126

answers:

1

I have a standard table view, with a UISearchController implemented via a NIB. I want to mimic what happens when the user clicks "Cancel" in the search bar - the normal behaviour is that the search bar goes away and the table returns to its original state. Basically, I want to have the same happen when the user selects an item that appears in their search results.

I can't find anywhere the process of what happens when the user clicks "Cancel".

A: 

Usually, the searchBarCancelButtonClicked: method looks something like this:

yourSearchBar.text = @"";
[yourTableView reloadData];
[yourSearchBar resignFirstResponder];
Felixs
If I do those three things, the result is that the keyboard is dismissed and the search results table goes, but the main table behind remains dimmed and the search field is still visible. Clicking in the dimmed table completes the steps that I want to happen: the search bar goes and the main table is made visible.
Philip McDermott
There is no search results table; it's the same table which has had some of its cells removed because of the search, unless you're using a UISearchDisplayController.
Felixs
Sorry, I just meant the different states of the table. From my original question: "I want to mimic what happens when the user clicks "Cancel" in the search bar - the normal behaviour is that the search bar goes away and the table returns to its original state. Basically, I want to have the same happen when the user selects an item that appears in their search results.
Philip McDermott
Does selecting a cell load a detail view? If so, you probably don't want to do [yourTableView reloadData]; because when they return, they would expect the results of their search to still be there. Drilling down into a detail view also removes the keyboard automatically. If this is not the case, then just implement my answer in didSelectRowAtIndexPath:, probably without the [yourTableView reloadData];
Felixs