2014-10-17 57 views
3

我编程方式创建一个UISearchController活跃,并在viewDidLoad中scopeBar不要下的UISearchBar显示,当它是首次

UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; 
searchResultsController.tableView.dataSource = self; 
searchResultsController.tableView.delegate = self; 
[searchResultsController.tableView registerNib:musicNib forCellReuseIdentifier:@"MusicCell"]; 

self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController]; 
self.searchController.searchResultsUpdater = self; 
UISearchBar *searchBar = self.searchController.searchBar; 
searchBar.scopeButtonTitles = @[@"Album", @"Artist", @"Song"]; 
searchBar.showsScopeBar = YES; 
searchBar.selectedScopeButtonIndex = 0; 
searchBar.delegate = self; 

self.tableView.tableHeaderView = self.searchController.searchBar; 

设置范围按钮标题但是,当我在搜索栏搜索时查看加载。范围栏不显示。第二个我在搜索栏中搜索,范围栏显示。这是怎么回事?基于您的评论

searchBarDisplayController.searchBar.showsScopeBar = NO; 
searchBarDisplayController.searchBar.scopeButtonTitles = nil; 

,放在searchDisplayControllerWillBeginSearch上面的代码:

first time search, scope bar don't show second time search, scope bar shows

回答

-1

您可以删除searchBar.showsScopeBar = YES;

1

试试这个委托方法。这应该工作。