0

ナビゲーションコントローラのバーのtitleViewにUISearchControllerの検索バーを埋め込みしようとしています。正確にはこれはAppleがUICatalogのサンプルコードで見て動作しますすることができます。ナビゲーションバーに埋め込まれたUISearchControllerのUISearchBar:最初のレスポンダにはなりません

// Create the search results view controller and use it for the UISearchController. 
AAPLSearchResultsViewController *searchResultsController = [self.storyboard instantiateViewControllerWithIdentifier:AAPLSearchResultsViewControllerStoryboardIdentifier]; 

// Create the search controller and make it perform the results updating. 
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController]; 
self.searchController.searchResultsUpdater = searchResultsController; 
self.searchController.hidesNavigationBarDuringPresentation = NO; 

/* 
    Configure the search controller's search bar. For more information on how to configure 
    search bars, see the "Search Bar" group under "Search". 
*/ 
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal; 
self.searchController.searchBar.placeholder = NSLocalizedString(@"Search", nil); 

// Include the search bar within the navigation bar. 
self.navigationItem.titleView = self.searchController.searchBar; 

self.definesPresentationContext = YES; 

私はこのコードで同じことをしよう:私は、デバイスまたはシミュレータでそれを実行すると

self.searchSuggestionsController = [[SearchSuggestionsTableViewController alloc]initWithStyle:UITableViewStylePlain]; 
self.searchSuggestionsController.delegate = self; 
self.searchController = [[UISearchController alloc]initWithSearchResultsController:self.searchSuggestionsController]; 
self.searchController.delegate = self; 
self.searchController.searchResultsUpdater = self.searchSuggestionsController; 
self.searchController.searchBar.delegate = self; 

self.searchController.dimsBackgroundDuringPresentation = YES; 
[self.searchController setHidesNavigationBarDuringPresentation:NO]; 



self.searchController.searchBar.searchBarStyle = UISearchBarStyleProminent; 
[self.searchController.searchBar setPlaceholder:NSLocalizedString(@"Search", nil)]; 

[self.navigationItem setTitleView:self.searchController.searchBar]; 

if (self.searchQuery) { 
    [self.searchController.searchBar setText:_searchQuery.queryString]; 
} 

self.definesPresentationContext = YES; 

しかし、ナビゲーションバーの検索バーが最初のレスポンダになることはありません。キーボードが表示されない、テキストを入力することはできません。私はできることは、クリアボタンを使用し、テキストがクリアされますが、まだ私はテキストを入力することはできません。

アイデア?

+0

ところで:ナビゲーションバースタイルを変更しても役に立ちません – plaetzchen

答えて

0

UISearchBarDelegate

を実装しようとしてsearchBarTextDidEndEditingコールresignFirstResponder()

+0

試しましたが、デリゲートメソッドはタップでも呼び出されません。 – plaetzchen

+0

UISearchBarDelegateとUISearchControllerDelegateの両方のプロトコルに準拠しましたか? :S –

+0

両方のプロトコルとすべてのすべての組み合わせに対してYes。それは変わらない – plaetzchen

0

旧質問に、その後searchBarTextDidBeginEditing

searchBarbecomeFirstResponder()を呼び出すが、ちょうど同様の問題を抱えていました。 VCヒイラキーの有効なナビゲーションコントローラに「searchBar」を埋め込んでください。それは私の間違いだった。これはうまくいく。

CCCTestVC *tVC = [[CCCTestVC alloc] init]; 
UINavigationController *nC = [[UINavigationController alloc] initWithRootViewController:tVC]; 
[self.navigationController presentViewController:nC animated:YES completion:nil]; 

これとは対照的に、

CCCTestVC *tVC = [[CCCTestVC alloc] init]; 
[self.navigationController pushViewController:tVC animated:YES]; 
関連する問題