Search code examples
iosuiviewcontrollerswift3uistoryboarduisearchcontroller

UISearchController ResultsController appearing over navigation bar


I have a UISearchController which has it's own custom results controller, rather than filtering the contents in the immediate view.

The UISearchBar appears in the navigation bar correctly, but when I begin typing characters into the search box, my custom controller appears, and fills the entire screen, covering up the navigation bar and the window I'm typing my query into.

This used to work, but I recently changed my storyboard to have the UINavigationController as the entry point, leading into a UITabBarController, which then had it's tabbed controllers.

The UITabBarController now has all the logic for the searches, so it can route the actions taken on the search results to the appropriate tab via a protocol I've implemented.

Below is my storyboard, note, that the custom search result controller is the item sitting below the UITabBarController, and the unattached item on the top right corner, is used via a library and is attached to the top tab's controller internally.

I'm starting to wonder if this specific configuration works? Can I have the UINavigationController in front of the UITabBarController?

I wanted to have a persistent search bar up top with all the shared search code in one spot (UITabBarController) rather than put a UINavigationController in front of each tab?

If this should work, are there any ideas why the custom search results controller is now covering the entire screen, instead of going under the navigation bar?

enter image description here


Solution

  • Turns out the issue was I needed to call

    definesPresentationContext = true
    

    In the view controller that was already being displayed (tab 1)

    When I moved the search code over to the UITabBarController, I moved that with it.