Question

I have created a UITableViewViewController with a UISearchDisplayController. When i search in the searchbar the values will show in en extra tableview.

I set both background on clearColor, therefore I can see that both tableviews have data.

How can i handle that there will be shown only the searched data when using the searchbar and after that the normal data will show?

That's the methods I use for the UISearchDisplayController:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    self.filteredList = [SearchHelper getSearchedItemsAsArray:[self.arrayWithCompanies mutableCopy] searchWord:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    return YES;
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
    [SearchHelper getSearchedItemsAsArray:[self.arrayWithCompanies mutableCopy] searchWord:self.searchDisplayController.searchBar.text scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
    return YES;
}

Thanks for help and tips

Was it helpful?

Solution

There are two possibilities

1) Use searchbar control only instead of UISearchDisplayController and fill data in tableview as per your need !!

2) Hide the actual tableview while searching and data will be displayed in UISearchDisplayController tableview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top