Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make UISearchController inactive when switching views

A little background on the setting of our views:

Inside a NavigationController, we have a UITabBarController (with 3 tabs) with a UIViewController that has a UISearchController.

There is an error that if we leave the UISearchController active and switch to another view, when we return to the search view the entire screen is black. However, when the UISearchController is not active and we switch views this does not happen.

We have tried to set the controller to not be active when segueing between views; however, when the UISearchController is active none of the segueing events get called (no log prints appear from viewWillDissapear, viewWillAppear, etc.)

Looking on other threads, we tried setting self.definesPresentationContext = true but that does not work.

Has anyone else had this problem or know how to fix it?

like image 973
Jared Katzman Avatar asked Apr 26 '15 20:04

Jared Katzman


People also ask

How to show search results in uisearchcontroller?

The initializer to UISearchController can take an argument that can specify a different view controller to show the search results. I think the most common use case is to show the search results in the same view controller that has the table view. Passing nil indicates that we do not want another view controller to show the search results.

Can I use a uisearchcontainerviewcontroller on iOS?

Don’t use a UISearchContainerViewController on iOS. Specify a second view controller for displaying search results when you call init (searchResultsController:). When the user interacts with the search bar, the search controller automatically displays the results controller with the results you specify.

What is the uisearchcontroller in Interface Builder?

The UISearchController was introduced a couple years ago in iOS 8 to replace the now deprecated UISearchDisplayController. In the new search controller, it is easier to add search to your table views. As of Xcode 8.1, the UISearchController has not been added to Interface Builder, so you have to add it programmatically.

What happened to uisearchdisplaycontroller in iOS 8?

Your users will appreciate searches that are intelligent and fast. If you’ve worked with searching table views in iOS in the past, you may be familiar with UISearchDisplayController. Since iOS 8, Apple has deprecated this class in favor of UISearchController, which simplifies the entire search process.


1 Answers

Try to set the searchbarController active like this

self.resultSeachController.active = false

before you move on the next View

like image 114
Hieu Duc Pham Avatar answered Sep 23 '22 17:09

Hieu Duc Pham