UISearchController
A view controller that manages the display of search results based on interactions with a search bar.
Declaration
@MainActor class UISearchControllerOverview
Use a search controller to provide a standard search experience of the contents of another view controller. When the user interacts with a UISearchBar, the search controller coordinates with a search results controller to display the search results.
In iOS, incorporate the search controller’s searchBar into your own view controller’s interface. Display your view controller in whatever way is appropriate for your app. See Displaying searchable content by using a search controller and Using suggested searches with a search controller to learn how to implement a search controller in your app.
In tvOS, start with a UISearchContainerViewController to manage the presentation of the search controller. See UIKit Catalog (tvOS): Creating and Customizing UIKit Controls to learn how to implement a search controller embedded inside a UISearchContainerViewController object.
Display search results
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. If your results view is full-screen in tvOS, set the searchControllerObservedScrollView to the results controller as well, so the search bar scrolls with your content view.
Provide a UISearchResultsUpdating object to the search controller’s searchResultsUpdater property. Typically, the view controller with your searchable content also acts as the search results updater object, but you can use another object if you prefer. When the user interacts with the search bar, the search controller calls the appropriate UISearchResultsUpdating method, giving your object the opportunity to perform the search and update the contents of your search results view.
Customize transitions
To customize the presentation or dismissal of the search results controller, set the search controller’s delegate property to an object that conforms to the UISearchControllerDelegate protocol. Then implement delegate methods in this object to receive presentation and dismissal events from the search controller.
Topics
Creating a search controller
Responding to presentation and dismissal
Managing the search results
Configuring the search interface
obscuresBackgroundDuringPresentationhidesNavigationBarDuringPresentationautomaticallyShowsCancelButtonautomaticallyShowsSearchResultsControllershowsSearchResultsControllersearchBarPlacementignoresSearchSuggestionsForSearchBarPlacementStackedautomaticallyShowsScopeBarscopeBarActivationUISearchController.ScopeBarActivation
Providing search suggestions
searchSuggestionsignoresSearchSuggestionsForSearchBarPlacementStackedUISearchSuggestionItemUISearchSuggestion