当我开始在searchBar中录制时,会出现结果弹出窗口。它只发生在iPad上,在iPhone上一切正常。 我怎么能解雇这个popover?我在tableView中显示结果,我不需要这个popover。
- (void)viewDidLoad
{
[super viewDidLoad];
searchData = [[NSMutableArray alloc] init];
originChannels = [[NSArray alloc]init];
channels = [[NSArray alloc] init];
searchBar = [[UISearchBar alloc]
initWithFrame:CGRectMake(0.0f,0.0f,320.0f,0.0f)];
searchBar.placeholder =@"Search";
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
[searchBar sizeToFit];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
self.navigationItem.titleView = searchBar;
self.navigationItem.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
}
搜索:
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
channels = searchData;
if([searchString isEqualToString:@""])
{
channels = originChannels;
[searchBar resignFirstResponder];
}
[self.tableView reloadData];
[self.collectionView reloadData];
return YES;
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[searchData removeAllObjects];
Channel *channel;
for(channel in originChannels)
{
NSRange range = [channel.name rangeOfString:searchText
options:NSCaseInsensitiveSearch];
if (range.length > 0)
[searchData addObject:channel];
}
}
此
[searchDisplayController setActive:NO animated:YES];
对我没有帮助。
我的解决方案:
这解决了我的问题
searchDisplayController.displaysSearchBarInNavigationBar=YES;