5

プログラムで UISearchController を作成し、viewDidLoad でスコープ ボタンのタイトルを設定しました。

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;

しかし、ビューがロードされたときに検索バーで検索すると。スコープバーが表示されません。検索バーで 2 番目に検索すると、スコープ バーが表示されます。どうしたの?

初回検索、範囲バーが表示されない 2 回目の検索でスコープ バーが表示される

4

3 に答える 3

1

これを試して:

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

あなたのコメントに基づいて、上記のコードを searchDisplayControllerWillBeginSearch: delegate メソッドに入れます。それはうまくいくはずです。

于 2016-03-31T11:06:04.183 に答える
-2

削除できますsearchBar.showsScopeBar = YES;

于 2015-03-03T09:37:02.560 に答える