The search bar is disabled when using the UISearchController with the UITabBarController inside the UINavigationController

I have an application with a UITabBarController in a UINavigationController . ( UITabBarController not the "Initial View Controller" for the history pane.)

In the initial UIViewController , I have a UISearchController that allows me to search for content from a remote source.

This worked fine until I added a UITabBarController . Now the search bar is displayed normally in the default state, but as soon as you start typing it inside, it gets up the top edge of the view.

I understand that this probably has a lot in common with automaticallyAdjustsScrollViewInsets , extendedLayoutIncludesOpaqueBars and / or edgesForExtendedLayout , but in all my settings I was unable to find a magic combo to get the UISearchController so as not to push myself to the top of the view.

Any ideas on how to make it work?

See these screengrabs from this sample project :

Initial View:

Initial view

The search text field becomes the first responder:

Search textbox becomes first responder

After entering a word and pressing, enter:

enter image description here

+3
source share
2 answers

I also ran into this problem, and here is the solution: setting definesPresentationContext = true on UITabBarController instead of the table view controller seems to fix it.

Apparently you need to go all the way to the navigation controller in the container hierarchy. Not the most obvious thing in the world if you ask me.

0
source

Although definesPresentationContext worked for me before, since in iOS 10 at some point I had to disable the Configure scroll scrolls on my search results presentation controller. More about my answer on a UISearchBar is disabled when using the UINavigationController inside a UITabBarController

0
source

Source: https://habr.com/ru/post/1237718/


All Articles