It's hard tell without more code, but I think you'll need to show/hide your two table views based on the search string.
If the string is empty, this will hid your searchResultsTableView
and show your other table view which I'm I'm lovingly calling whatEverYouCalledYourOtherTableView
.
If your string is not empty you do your search, show searchResultsTableView
, hide whatEverYouCalledYourOtherTableView
and reload the data for searchResultsTableView
.
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
if ([searchString isEqualToString:@""])
{
self.searchDisplayController.searchResultsTableView.hidden = YES;
self.searchDisplayController.whatEverYouCalledYourOtherTableView.hidden = NO;
}
else
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
self.searchDisplayController.searchResultsTableView.hidden = NO;
self.searchDisplayController.whatEverYouCalledYourOtherTableView.hidden = YES;
[self.searchDisplayController.searchResultsTableView reloadData];
}
return YES;
}
Also your filterContentForSearchText
is wrong. You have an array of dictionaries not strings. First grab just the strings, then run your search. You'd be better off creating a dictionary of strings right away, the simplest way of getting your search to work is like this.
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[self.searchResults removeAllObjects];
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@", searchText];
NSMutableArray *activityArray = [[NSMutableArray alloc] init];
for (int i = 0; i < [self.tableData count]; i++)
{
[activityArray addObject:self.tableData[i][@"activity"]];
}
self.searchResults = [NSMutableArray arrayWithArray:[activityArray filteredArrayUsingPredicate:resultPredicate]];
}