我在弹出窗口中嵌入了一个UIViewController。该控制器有两个子视图,UINavigationBar
和MapView
。我尝试实现新的搜索控制器,即UISearchController
,因为在iOS8中不推荐使用UISearchDisplayController。
当我点击搜索栏(显示两个范围)时,一切都很好,导航栏仍然可见。但是当我开始在搜索栏中输入时,导航栏和键盘消失,取而代之的是昏暗的地图视图。我尝试在self.searchController.hidesNavigationBarDuringPresentation = NO;
方法和updateSearchResultsForSearchController:
方法中添加searchBarShoulBeginEditing:
,但没有得到任何结果。 (请注意,控制器viewDidLoad
定义了self.definesPresentationContext = YES;
)
是否有任何想法强制导航随时显示?
答案 0 :(得分:0)
首先在ViewDidLoad中设置此属性self.definesPresentationContext = YES;
。然后实施searchBarTextShouldBeginEditing
和searchBarTextDidBeginEditing
方法:
-(void)searchBarTextShouldBeginEditing:(UISearchBar *)searchBar {
[searchControllerMain setActive:YES];
[searchControllerMain.searchBar becomeFirstResponder];}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
[searchControllerMain setActive:YES];
[searchControllerMain.searchBar becomeFirstResponder];
searchControllerMain.hidesNavigationBarDuringPresentation = NO;
}
它会起作用!!