Joachim Kurz Joachim Kurz - 1 year ago 68
iOS Question

UISearchDisplayController configure "no results" view not to overlap tableFooterView

I have a list of things provided by the system (e.g. brands) which are not user editable but have to change from time to time.


These things are displayed in a table view and are searchable using the default UISearchDisplayController. However, as the list of things surely isn't complete I want to give users the ability to request the addition of other things to the list.
To do so I added a table footer view to both the original table view and the search results table view, which provides a button to send a mail.


It works fine as long as the search results table view still contains entries. My table footer view is displayed below the search results and everything is fine.

However, if no results are found for a search term, the search display controller displays a "no result" label centered over the table view. This usually looks great, like this:

default "no results" screen

But since my tableFooterView is still displayed (which I want it to be!) the "no results" label overlaps my footer view and it looks crappy:

enter image description here

I think in my case I don't need the "no result"s label, since my footer view makes it reasonable clear that there are no results and what to do about it. I don't mind it either, as long as it doesn't overlap.


How can I either

  • make the search view not display the "No Results" label

  • or configure how it is displayed (-> not overlapping)

If this is not possible I'm also open to suggestions for others ways of displaying the footer view (not as footer), which would not have this problem. But I like the solution since I can use it in both cases (normal table view and search results table view) without having to change anything.

Answer Source

First of all, it is important to keep in mind that using UISearchDisplayController is a trade-off between customizability and convenience. You get a lot of automatic stuff for free, but if you require a lot of customization it might not suit your needs. It works best as a drop-in solution, and if you'd really like to use it, I recommend you work your app around it instead of trying to hack its behavior.

With that said, why don't you make the UITableView return a single row when there are no results? This row could either be empty, display some boilerplate text or an image (sad face or something humorous that matches the app).

Having a single row to be presented, the default "No Results" label from UISearchDisplayController would not be shown. This is the default behavior for a lot of Apps, like Instagram (check out the Explore tab), Kindle and the default, although they are probably not using UISearchDisplayController.

If you find that this workaround doesn't fit your app, you could also try making the "Missing a Brand" view into the header view of the first section of the UISearchResultsTableView (instead of the footer view). That way, the "No Results" label would be displayed below it. Combining this idea with a single empty row would even work better.

A third option would be to insert this view on top of the UISearchResultsTableView. This could be done every time there were no results (properly removing it when necessary) or just a single time, using its hidden property to show or hide it instead.

Any other method for hiding this label is probably hacky, like this one: Although easier on your current logic, it might have negative consequences later on, so it's possibly the worst path to follow.