2010-10-27 3 views
0

J'ai essayé pendant des heures mais je n'arrivais pas à comprendre pourquoi le résultat ne s'affichait pas. Il montre toujours tous les résultats. Je ne suis pas sûr de ce que je fais mal.shouldReloadTableForSearchString n'affiche pas le résultat filtré

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString 
{ 
    [self filterContentForSearchText:searchString scope: 
    [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; 
    // Return YES to cause the search result table view to be reloaded. 
    return YES; 
} 


- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope 
{ 
/* 
    Update the filtered array based on the search text and scope. 
    */ 

[self.filteredListContent removeAllObjects]; // First clear the filtered array. 
    //for loop here 
NSLog(@"%i", [filteredListContent count]); 
    //filteredListContent contains correct number of filtered items 
} 

Répondre

1

Cela fonctionne. Je n'utilisais pas le tableau de résultats filtré dans la méthode numberOfRowsInSection

was: 
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
      return [self.persons count]; 
    } 


changed to: 
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     if (tableView == self.searchDisplayController.searchResultsTableView) 
     { 
      return [self.filteredListContent count]; 
     } 
     else 
     { 
      return [self.persons count]; 
     } 
    } 
Questions connexes