0
votes

I really do not know what I am doing wrong. I have tried different versions of implementing the SearchDisplayController for my table but it is still not working. Everything seems to work fine. Echoing out values like counts of used arrays gave me correct numbers. Even the search part is ok because I was in position to even echo the found string/s. The only problem is that the found result is not displayed on my table. As soon as typing starts by typing into the searchbar textfield, a black white table with empty rows will just appear. I am somehow really frustrated as this has taken two days now. Any tip?

This is the the code that does the searching: -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

if(searchText.length == 0)
{
    isFiltered = FALSE;
}
else
{
    isFiltered = TRUE;

    if (filteredTableData == nil)
        filteredTableData = [[NSMutableArray alloc] init];
    else 
        [filteredTableData removeAllObjects];

    for (NSDictionary *d in self.countries)
    {
        NSString *strData = [d valueForKey:@"cname"];
        NSRange nameRange = [strData rangeOfString:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
        if(nameRange.location != NSNotFound)
        {
            [filteredTableData addObject:d];
        }
    }
}
[self.tableView reloadData];

}

1

1 Answers

0
votes

If you are using a UISearchDisplayController you will need to call something like this:

[self.searchDisplayController.searchResultsTableView reloadData];

instead of

[self.tableView reloadData];