IOS8 如何限制 UISearchController 隐藏视图导航栏

How to restrict UISearchController from hiding view Navigation Bar in IOS8

我在弹出窗口中嵌入了一个 UIViewController。这个控制器有两个子视图,一个 UINavigationBar 和一个 MapView。我尝试实现新的搜索控制器,即 UISearchController,因为 UISearchDisplayController 在 iOS8.

中已弃用

当我点击搜索栏(显示两个范围)时,一切正常,导航栏仍然可见。但是当我开始在搜索栏中输入内容时,导航栏和键盘消失了,取而代之的是昏暗的地图视图。我尝试在 updateSearchResultsForSearchController: 方法和 searchBarShoulBeginEditing: 方法中添加 self.searchController.hidesNavigationBarDuringPresentation = NO;,但没有结果。 (注意控制器viewDidLoad定义self.definesPresentationContext = YES;

任何时候强制显示导航的想法?

首先在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;
}

它会起作用的!!