Note that there are some explanatory texts on larger screens.

plurals
  1. POsearch method not working after second hit
    text
    copied!<p>I've a problem with my <code>UISearchDisplayController</code>, the search is not working properly.</p> <p>This is my code:</p> <pre><code> - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope { [self.searchResults removeAllObjects]; for (int i = 0; i &lt; [temp_category count]; i++) { BOOL foundResult = FALSE; if ([[temp_category objectAtIndex:i] rangeOfString:searchText].location != NSNotFound) { foundResult = TRUE; } if ([[price_producttitle objectAtIndex:i] rangeOfString:searchText].location != NSNotFound) { foundResult = TRUE; } if ([[price_type objectAtIndex:i] rangeOfString:searchText].location != NSNotFound) { foundResult = TRUE; } if ([[price_description objectAtIndex:i] rangeOfString:searchText].location != NSNotFound) { foundResult = TRUE; } if (foundResult) { NSNumber *result = [NSNumber numberWithInt:i]; if ([self searchResults] == nil) { NSMutableArray *array = [[NSMutableArray alloc] init]; [self setSearchResults:array]; [array release]; } [searchResults addObject:result]; } } NSLog (@"array = %i", [searchResults count]); NSLog(@"%@",searchResults); } -(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; } </code></pre> <p>But I'm still confused, because when I start a search with the first letter, it gives the correct hits. But when I enter the second letter, it only shows one result (while there are more, as far as I know from my data sample). I'm doing something incorrectly. I think it has something to do with when the user enters text, but I'm confused which method I should use.</p> <p>The code I now have is a combination of: <a href="http://ygamretuta.me/2011/08/10/ios-implementing-a-basic-search-uisearchdisplaycontroller-and-interface-builder/" rel="nofollow noreferrer">this</a> tutorial and <a href="https://stackoverflow.com/questions/8169889/searchdisplaycontroller-search-multiple-arrays">this</a> SO question.</p> <p>Can someone give me a hint in the good direction? Displaying the results is fine, only this aspect bothers me. I think it has something to do with firing the method and <code>[self.searchResults removeAllObjects];</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload