UISearchDisplayController

Important: UISearchDisplayController is deprecated in iOS 8. (Note that UISearchDisplayDelegate is also deprecated.) To manage the presentation of a search bar and display search results in iOS 8 and later, instead use UISearchController.
More...

A search display controller manages the display of a search bar, along with a table view that displays search results.

You initialize a search display controller with a search bar and a view controller responsible for managing the data to be searched. When the user starts a search, the search display controller superimposes the search interface over the original view controller’s view and shows the search results in its table view.

In addition to managing the searchable data, the original view controller typically plays four more roles you need to fill when using a search display controller. Those roles are the following:

Data source for the search results table view (searchResultsDataSource), which provides the data for the results table.

Delegate for the search results table view (searchResultsDelegate), which responds to the user’s selection of an item in the results table.

Delegate for the search display controller (delegate), which responds to events such the starting or ending of a search, and the showing or hiding of the search interface.

As a convenience, this delegate may also be told about changes to the search string or search scope, so that the results table view can be reloaded.

Typically, you initialize a search display controller from a view controller (usually an instance of UITableViewController) that’s displaying a list. See the Simple UISearchBar with State Restoration sample code project for an example of how to configure a search display controller in Interface Builder. To perform configuration programmatically, set self for the search display controller’s view controller and search results data source and delegate, as shown here:

searchController=[[UISearchDisplayControlleralloc]

initWithSearchBar:searchBarcontentsController:self];

searchController.delegate=self;

searchController.searchResultsDataSource=self;

searchController.searchResultsDelegate=self;

If you follow this pattern, then in the table view data source and delegate methods you can check the methods’ table view argument to determine which table view is sending the message:

A view controller or search bar can be associated with only a single search display controller at a time. If a search display controller is destroyed (for example, in response to a memory warning), then you can create a new one and associate it with the original view controller or search bar.

Declaration

Discussion

The default value is NOfalse.

If you set this value directly, any change is performed without animation. Use setActive:animated: if a change in state should be animated.

When the user focus in the search field of a managed search bar, the search display controller automatically displays the search interface. You can use this property to force the search interface to appear.

Declaration

Parameters

YEStrue to display the search interface if it is not already displayed; NOfalse to hide the search interface if it is currently displayed.

animated;

YEStrue to use animation for a change in visible state, otherwise NOfalse.

Discussion

When the user focus in the search field of a managed search bar, the search display controller automatically displays the search interface. You can use this method to force the search interface to appear.

Availability

Declaration

Swift

var displaysSearchBarInNavigationBar: Bool

Objective-C

@property(nonatomic,assign)BOOLdisplaysSearchBarInNavigationBar

Discussion

When you return YEStrue to display the search bar in a navigation bar, the system uses the search display controller’s navigationItem property and ignores the navigation item, if set, of the searchContentsController view controller. The displayed search field occupies as much width in the navigation bar as possible.

A search bar displayed in a navigation bar cannot have a scope bar.

Important

The system raises an exception if you set the showsScopeBar property to YEStrue in a search bar that is displayed in a navigation bar.