搜索栏消失在ios UIsearchcontroller中 [英] search bar getting disappeared in ios UIsearchcontroller

查看:514
本文介绍了搜索栏消失在ios UIsearchcontroller中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UISearchController,当我单击搜索栏时,我得到了动画,好像搜索栏将进入带有淡入淡出动画的所显示搜索控制器的导航栏一样,但是它消失了,并且所显示的键盘停留在那里.

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.

在viewcontroller.m中,viewdidload方法,相关部分:

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];

SearchResultsViewController是带有过滤数组的UIViewController,该数组从ViewController中的-(void)updateSearchResultsForSearchController:(UISearchController *)searchController方法获取其值

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

随着搜索栏的消失,我试图将搜索栏作为ViewController中TableView的标题,它可以正常工作.但是当我只是将搜索栏视图作为自定义创建的视图而不是表头时,它就消失了.

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

推荐答案

尝试以下两种设置:

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

这篇关于搜索栏消失在ios UIsearchcontroller中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆