user162635
user162635

Reputation: 13

Dismiss Popover from SearchDisplayController

I programmed a SearchBar but no ot in the interface builder b< dragging the search to the tableView. The SearchResult was shown in an other TabelView. The search works great. But every time I search it shows me this SearchResult Popover. Can I delete this Popover?

[SetShowsSearchResultsButton self.searchDisplayController.searchBar: NO]; It also does not work

here is some code

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [appDelegate.searchSource removeAllObjects];
    if (0  == [searchString length]) {
        NSLog(@"LEER");
        appDelegate.gefunden=NO;
        [appDelegate.rootViewController.tableView.tableView reloadData];
        [SearchBar1 resignFirstResponder];
    }
    for (NSArray *myPoi in appDelegate.poiList)
    {
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF contains[c] %@)", searchString];
        BOOL resultName = [predicate evaluateWithObject:[myPoi valueForKey:@"name"]];
        if (resultName) {
            appDelegate.gefunden = YES;
            [appDelegate.searchSource addObject:myPoi];
            [appDelegate.rootViewController.tableView.tableView reloadData];
            [self.searchDisplayController setActive:NO animated:YES];
            [self.SearchBar1 becomeFirstResponder];
        }
    }
    return YES;
}

and in viewdidload

self.searchDisplayController.searchResultsDataSource = appDelegate.rootViewController.tableView.tableView.dataSource;

Thanks

Upvotes: 1

Views: 783

Answers (2)

RK-
RK-

Reputation: 12211

You can do this by setting the controller to be inactive once the search ends:

- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller{

    [controller setActive:NO animated:YES];
}

Upvotes: 1

Tobias
Tobias

Reputation: 1577

In IB try to set the searchResultsDelegate, searchResultsDataSource, searchContentsController values of your SearchDisplayController to Files Owner und put your code from

- (BOOL)searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchString:(NSString*)searchString

to

- (void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)searchText

That should do the trick.

Upvotes: 1

Related Questions