iOS UISearchBar:设置showsScopeBar = YES& scopeButtonTitles不是nil,但scopeBar没有显示

时间:2013-08-01 03:59:56

标签: ios iphone objective-c uisearchbar

我要疯了!这是我的问题。我想在搜索后开始搜索并隐藏它时显示UISearchBar.ScopeBar。我找到了一个解决方案帖子 iPhone : hide a scopeBar from a searchBar 但它对我不起作用。 这是我的代码:

   self.friendSearchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"Phone",@"Name", nil];
   self.friendSearchBar.selectedScopeButtonIndex = 0;
   self.friendSearchBar.showsScopeBar = YES;

1 个答案:

答案 0 :(得分:0)

您好,搜索栏在搜索后消失,您需要实现此功能。

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
YourScopeGoesHere scopeKey = controller.searchBar.selectedScopeButtonIndex;
[self searchForText:searchString scope:scopeKey];
return YES;
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
NSString *searchString = controller.searchBar.text;
[self searchForText:searchString scope:searchOption];
return YES;
}