views:

16

answers:

1

I have been trying for hours but couldn't figure out why it doesn't show the filtered result. It always shows all the results. I'm not sure what I am doing wrong.

- (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
}
A: 

It works. I wasn't using the filtered result array in numberOfRowsInSection method

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];
        }
    }
gangt