scopeBar不要下的UISearchBar显示,当它是首次
问题描述:
我编程方式创建一个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上面的代码:
答
您可以删除searchBar.showsScopeBar = YES;
答
试试这个委托方法。这应该工作。