A view controller that manages the display of search results based on interactions with a search bar.
- iOS 8.0+
- tvOS 9.0+
You use a search controller in tandem with your existing view controllers. When you have a view controller with searchable content, incorporate the search bar of a
UISearch object into your view controller’s interface. When the user interacts with that search bar, the search controller automatically displays a new view controller with the search results that you specify.
A search controller works with two custom view controllers that you provide. The first view controller displays your searchable content and the second displays your search results. The first view controller is part of your app’s main interface and you display it in whatever way is appropriate for your app. You pass the second view controller to the
init(search method when you initialize your search controller, and the search controller displays that view controller at appropriate times.
Each search controller provides a
UISearch object that you must incorporate into the user interface of your initial view controller. Add this object to the view containing your searchable contents. When the user taps the search bar to enter a search term, the search controller automatically displays your search results view controller and notifies your app that the search process has begun.
When the user interacts with the search bar, the search controller notifies the object in its
search property. You provide the search results updater object, which must conform to the
UISearch protocol. You use the methods of that protocol to search your content and deliver the results to your search results view controller. 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.
To customize the presentation or dismissal of the search results controller, assign an object to the search controller’s
delegate property. Delegate objects must conform to the
UISearch protocol. You use the methods of that protocol to be notified when the search controller itself is activated and when the search results controller is presented or dismissed.
For iOS, see Displaying Searchable Content by Using a Search Controller to learn how to implement a search controller in your app.
For tvOS, see UIKit Catalog (tvOS): Creating and Customizing UIKit Controls to learn how to implement a search controller embedded inside a