0

I have a UISearchBar linked to a table view, which works fine. As you're typing it filters the results as expected. When you press Search, however, the results all vanish, leaving an empty list (the unfiltered list doesn't return, not until you clear the search text or click cancel).

My question is a) why does this happen, or b) if there's no obvious answer, what method is called by default when you press Search?

I configured the search by inserting the "Search Bar and Search Display Controller" in the Interface Builder, then setting up the filtered results so they're displayed "if (tableView == self.searchDisplayController.searchResultsTableView)".

mazz0
  • 683
  • 2
  • 8
  • 19

1 Answers1

0

Assuming you have your delegates set properly, the method you're looking for is:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
jakenberg
  • 2,125
  • 20
  • 38
  • Yep, it's calling that, so the links are in place. I must be missing something though. Is there something I can put in there to redraw the search results view? – mazz0 Jun 11 '14 at 17:50
  • Ah, I fixed it with this: [self.searchDisplayController.searchResultsTableView reloadData]; – mazz0 Jun 11 '14 at 18:00
  • jsksma2 - do you have a link to the documentation where you found that, I was look through the docs on the Apple dev site and I couldn't find it, obviously I'm looking in the wrong place. I need another one: when you tap back in the search box (to edit the string) it blanks the results again, until you edit one character (at which point I assume it's calling searchDisplayControllerDidBeginSearch) so I need to put another redraw statement in there for when you first tap on the box. – mazz0 Jun 11 '14 at 18:02
  • Found it! https://developer.apple.com/library/ios/documentation/uikit/reference/UISearchBarDelegate_Protocol/Reference/Reference.html – mazz0 Jun 11 '14 at 18:09
  • https://developer.apple.com/library/ios/documentation/uikit/reference/UISearchBar_Class/Reference.html – jakenberg Jun 11 '14 at 18:09