2

I'm trying to add an UISearchBar to a table view I have defined in a ´nib´ file. I added a Search Bar and Search Display Controller in IB, linked the search bar outlet, and added this to the view controller's '.h' file:

@interface SearchListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>

Also, I've implemented the following delegate methods:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString 
{
   [self filterContentForSearchText:searchString scope:
   [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
   return YES;
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption 
{
   [self filterContentForSearchText:self.searchDisplayController.searchBar.text scope:
   [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
   return YES;
}

I find that shouldReloadTableForSearchString: method is called, but however shouldReloadTableForSearchScope: method is never called, so my table view data is not reloaded with search results... what could I be missing?

Thanks in advance

AppsDev
  • 12,319
  • 23
  • 93
  • 186
  • only putting `UISearchBarDelegate` in to .h class not enough you need to set it like `yourserchbar.delegate=self;` – Nitin Gohel Oct 21 '13 at 05:04

1 Answers1

4

You have to set delegate to self.

searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;

UISearchDisplayController Class Reference

Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
  • NOTE: UISearchDisplayDelegate is deprecated since IOS 8. Instead use UISearchDisplayController (as Rajneesh071 mentioned) – MLBDG Nov 28 '16 at 19:29