简体   繁体   English

Objective-C-滚动时,UISearchController结果在UISearchBar上重叠

[英]Objective-C - UISearchController results overlap on UISearchBar when scrolling

My goal is the following: have a UISearchBar which is always visible. 我的目标是:有一个始终可见的UISearchBar。 When it isn't active, there is some content on the bottom part of the controller. 当它不处于活动状态时,控制器的底部会包含一些内容。 When it becomes active, I want to display the results of the search in a UITableView that overlaps the UIController. 当它变为活动状态时,我想在与UIController重叠的UITableView中显示搜索结果。

The way my search is setup is the following: I have a fixed UIView on the top of my ViewController, created via Storyboard. 设置搜索的方式如下:通过Storyboard创建的ViewController顶部有一个固定的UIView。 In my viewDidLoad method, I add the searchController.searchBar to that UIView, so that the UISearchBar is permanently active. 在我的viewDidLoad方法中,将searchController.searchBar添加到该UIView中,以便UISearchBar永久处于活动状态。 I use the very useful following line to hide/display the searchResultsController: searchController.searchResultsController.view.hidden = FALSE; 我使用非常有用的以下行来隐藏/显示searchResultsController: searchController.searchResultsController.view.hidden = FALSE;

All of this works perfectly, except that when I display results, if I scroll down, the results are displayed on top of the UISearchBar. 所有这些都可以正常工作,除了当我显示结果时,如果向下滚动,结果将显示在UISearchBar的顶部。 在此处输入图片说明

What is the way to avoid this? 如何避免这种情况? I believe this is due to the fact that I use the following line: 我相信这是由于我使用了以下行:

[searchBarView addSubview:self.searchController.searchBar];

where searchBarView is an empty placeholder view which I create on my Storyboard and stick to the top. 其中searchBarView是一个空的占位符视图,我在情节提要板上创建并坚持到顶部。 This is the only way I found that have the searchBar displayed permanently. 这是我发现永久显示searchBar的唯一方法。 It's important to note that I don't use a navigation controller and that's why I don't add the searchController as a navigation item. 重要的是要注意,我没有使用导航控制器,这就是为什么我不将searchController添加为导航项的原因。

Thanks a lot for your help! 非常感谢你的帮助!

不要使用半透明的导航栏

self.navigationController.navigationBar.translucent = NO;

The way in which you are using UISearchController is totally wrong. 您使用UISearchController是完全错误的。 In case of searchcontroller, you must provide searchcontroller as result tableview's tableHeaderView. 如果是searchcontroller,则必须提供searchcontroller作为结果tableview的tableHeaderView。 Here you are adding searchcontroller into UIView and tableview at some other place. 在这里,您将在其他位置将searchcontroller添加到UIView和tableview中。 This is obviously not going to work. 这显然是行不通的。

Still you can try this possible ways --- 仍然可以尝试这种可能的方式-

  1. Make the topView an opaque.(dont provide transparency to that containerview) 使topView不透明。(不要为该containerview提供透明性)
  2. Use UISearchbar instead of using UISearchcontroller . 使用UISearchbar而不是UISearchcontroller

By this way, i think your problem will get solved. 这样,我认为您的问题将得到解决。

I have search this for many hours and final result was to put this line in viewDidLoad: 我已经搜索了很多小时,最终结果是将此行放入viewDidLoad中:

self.extendedLayoutIncludesOpaqueBars = YES;

Problem solved :) 问题解决了 :)

I hope it will working for you. 希望它对您有用。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM