search bar getting disappeared in ios UIsearchcontroller

一世执手 提交于 2019-12-08 04:26:02

问题


I am using UISearchController and when I click on the searchbar , I get animation as if the searchbar is going to the navigation bar of the presented searchcontroller with fading animation but it disappears and the keyboard presented is staying there.

In viewcontroller.m, viewdidload method, relevant part:

UIView *searchView = [[UIView alloc]initWithFrame:CGRectZero];
searchResultsViewController =[[SearchResultsViewController alloc]initWithNibName:@"SearchResultsViewController" bundle:nil];
self.searchController =[[UISearchController alloc]initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater=self;
self.searchController.dimsBackgroundDuringPresentation = NO;
searchView = self.searchController.searchBar;
self.definesPresentationContext = YES;
self.searchController.searchBar.delegate=self;
searchView.frame =CGRectMake(0, 50, [[UIScreen mainScreen]bounds].size.width, 40);
[self.view addSubview:searchView];

The SearchResultsViewController is a UIViewController with filtered Array which gets its value from -(void)updateSearchResultsForSearchController:(UISearchController *)searchController method in ViewController

As the search bar was disappearing, I tried to put the searchbar as a header for the TableView in ViewController, it is working normally . but when I just put the searchbar view as custom created view instead of table header, it is disappearing.

Any insight would be appreciated. Thanks


回答1:


Try with these two settings:

self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = NO;


来源:https://stackoverflow.com/questions/33494192/search-bar-getting-disappeared-in-ios-uisearchcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!