2014-10-17 42 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

試試這個委託方法。這應該工作。

相關問題