从SearchDisplayController中删除Popover

时间:2011-05-26 09:09:22

标签: controller uisearchbar uipopovercontroller popover searchdisplaycontroller

我编写了一个SearchBar,但在界面构建器b中没有<将搜索拖动到tableView。 SearchResult显示在另一个TabelView中。搜索效果很好。但是每次我搜索它都会向我显示这个SearchResult Popover。我可以删除这个Popover吗?

[SetShowsSearchResultsButton self.searchDisplayController.searchBar: NO]; 它也不起作用

这是一些代码

- (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;
}

并在viewdidload中

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

由于

2 个答案:

答案 0 :(得分:1)

在IB中尝试将SearchDisultsController的searchResultsDelegate,searchResultsDataSource,searchContentsController值设置为Files Owner并将代码设置为

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

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

这应该可以解决问题。

答案 1 :(得分:1)

您可以通过在搜索结束后将控制器设置为非活动状态来执行此操作:

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

    [controller setActive:NO animated:YES];
}