Alex Gosselin
Alex Gosselin

Reputation: 2930

Is there a simple way to detect if a UISearchBar is exiting "Search Mode"?

I'm trying to set up a UISearchBarDelegate

My first attempt was to clear the search results when searchBarShouldEndEditing: was called, but I discovered that this gets called when scrolling through the search results, which is not a time to be getting rid of the array of them.

My next attempt is searchBarCancelButtonClicked: - but this doesn't get called if the search bar is empty and they tap the space below (where a greyed out view of the table view is showing).

So how do you know when to switch from returning search results cells to returning regular table view cells?

Thanks for any help with this.

Upvotes: 0

Views: 364

Answers (1)

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

You can check which table view is requesting the cells. searchDisplayController.resultsTableView is what requests your search results cells. Just check for this in cellForRowAtIndexPath

Upvotes: 1

Related Questions