Is there a way to pre-populate the UISearchDisplayController with the results before the user starts typing in the SearchBar?

I would like to show past queries right after the search bar is activated. but even though the data source has these values, the search display controller does not invoke table presentation methods until the user begins to enter text. Is there a way to force this on a UISearchDisplayController?

+5
source share
1 answer

As long as your delegate is configured correctly, you can return any data set that you want.

 self.searchResults = @[@"some stuff", @"some more stuff", @"and so on..."];

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
   if (tableView == [[self searchDisplayController] searchResultsTableView]) {
     return [self.searchResults count];
   }
   else {
     return [self.data count];
   }
}
-1
source

All Articles