0
votes

My goal is the following: have a UISearchBar which is always visible. 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.

The way my search is setup is the following: I have a fixed UIView on the top of my ViewController, created via Storyboard. In my viewDidLoad method, I add the searchController.searchBar to that UIView, so that the UISearchBar is permanently active. I use the very useful following line to hide/display the 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. enter image description here

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. This is the only way I found that have the searchBar displayed permanently. 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.

Thanks a lot for your help!

3

3 Answers

0
votes

Don't use translucent navigation bar

self.navigationController.navigationBar.translucent = NO;
0
votes

The way in which you are using UISearchController is totally wrong. In case of searchcontroller, you must provide searchcontroller as result tableview's tableHeaderView. Here you are adding searchcontroller into UIView and tableview at some other place. 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)
  2. Use UISearchbar instead of using UISearchcontroller.

By this way, i think your problem will get solved.

0
votes

I have search this for many hours and final result was to put this line in viewDidLoad:

self.extendedLayoutIncludesOpaqueBars = YES;

Problem solved :)

I hope it will working for you. Thanks.