问题描述
|
我在界面生成器中编程了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;
谢谢
解决方法
在IB中,尝试将SearchDisplayController的searchResultsDelegate,searchResultsDataSource,searchContentsController值设置为Files Owner,然后将代码从
- (BOOL)searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchString:(NSString*)searchString
至
- (void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)searchText
这应该够了吧。
,您可以通过在搜索结束后将控制器设置为非活动状态来执行此操作:
- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller{
[controller setActive:NO animated:YES];
}