2015-05-14 44 views
1

我有一個UIViewController嵌入在彈出窗口。該控制器有兩個子視圖,分別爲UINavigationBarMapView。我嘗試實現新的搜索控制器,即UISearchController,因爲UISearchDisplayController在iOS8中已棄用。如何限制UISearchController從隱藏視圖導航欄IOS8

當我點擊搜索欄(顯示兩個範圍)時,一切正常,導航欄仍然可見。但是,當我開始在搜索欄中輸入內容時,導航欄和鍵盤消失,取而代之的是昏暗的地圖視圖。我試圖在updateSearchResultsForSearchController:方法以及searchBarShoulBeginEditing:方法中添加self.searchController.hidesNavigationBarDuringPresentation = NO;,但沒有得到任何結果。 (注意,控制器viewDidLoad定義爲self.definesPresentationContext = YES;

任何想法強迫導航隨時顯示?

+0

你可以發佈你的代碼(至少是與'UISearchController'相關的代碼部分) –

回答

0

首先在ViewDidLoad中設置此屬性self.definesPresentationContext = YES;。然後實現searchBarTextShouldBeginEditingsearchBarTextDidBeginEditing方法這樣:

-(void)searchBarTextShouldBeginEditing:(UISearchBar *)searchBar { 
[searchControllerMain setActive:YES]; 
[searchControllerMain.searchBar becomeFirstResponder];} 
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { 
[searchControllerMain setActive:YES]; 
[searchControllerMain.searchBar becomeFirstResponder]; 
searchControllerMain.hidesNavigationBarDuringPresentation = NO; 
} 

它將工作!

+0

沒有爲我工作。不過,我有一個導航控制器內的選項卡控制器。 – malhal