UISearchDisplayController Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iOS 3.0 and later. |
| Declared in | UISearchDisplayController.h |
Overview
A search display controller manages display of a search bar and a table view that displays the results of a search of data managed by another view controller.
You initialize a search display controller with a search bar and a view controller responsible for managing the original content to be searched. When the user starts a search, the search display controller is responsible for superimposing the search interface over the original view controller’s view and showing the search results. The results are displayed in a table view that’s created by the search display controller. In addition to the original view controller, there are logically four other roles. These are typically all played by the same object, often the original view controller itself.
The search results table view’s data source.
This object is responsible for providing the data for the results table.
The search results table view’s delegate.
This object is responsible for, amongst other things, responding to the user’s selection of an item in the results table.
The search display controller’s delegate.
The delegate conforms to the
UISearchDisplayDelegateprotocol. It is notified of events such as when the search starts or ends, and when the search interface is displayed or hidden. As a convenience, it may also be told about changes to the search string or search scope, so that the results table view can be reloaded.The search bar’s delegate.
This object is responsible for responding to changes in the search criteria.
Typically you initialize a search display controller from a view controller (usually an instance of UITableViewController) that’s displaying a list; you set self for the search display controller’s view controller and search results data source and delegate:
searchController = [[UISearchDisplayController alloc] |
initWithSearchBar:searchBar contentsController: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:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
if (tableView == self.tableView) { |
return ...; |
} |
// If necessary (if self is the data source for other table views), |
// check whether tableView is searchController.searchResultsTableView. |
return ...; |
} |
Tasks
Initialization
Displaying the Search Interface
-
activeproperty -
– setActive:animated:
Configuration
-
delegateproperty -
searchBarproperty -
searchContentsControllerproperty -
searchResultsTableViewproperty -
searchResultsDataSourceproperty -
searchResultsDelegateproperty -
searchResultsTitleproperty
Properties
active
The visibility state of the search interface.
Discussion
The default value is NO.
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.
Availability
- Available in iOS 3.0 and later.
Declared In
UISearchDisplayController.hdelegate
The controller’s delegate.
Availability
- Available in iOS 3.0 and later.
Declared In
UISearchDisplayController.hsearchBar
The search bar. (read-only)
Availability
- Available in iOS 3.0 and later.
Declared In
UISearchDisplayController.hsearchContentsController
The view controller that manages the contents being searched. (read-only)
Discussion
This is typically an instance of UITableViewController.
Availability
- Available in iOS 3.0 and later.
Declared In
UISearchDisplayController.hsearchResultsDataSource
The data source for the table view in which the search results are displayed.
Discussion
The default is nil.
Availability
- Available in iOS 3.0 and later.
Declared In
UISearchDisplayController.hsearchResultsDelegate
The delegate for the table view in which the search results are displayed.
Discussion
The default is nil.
Availability
- Available in iOS 3.0 and later.
Declared In
UISearchDisplayController.hsearchResultsTableView
The table view in which the search results are displayed. (read-only)
Discussion
This method creates a new table view if one does not already exist.
Availability
- Available in iOS 3.0 and later.
Declared In
UISearchDisplayController.hsearchResultsTitle
The title for the search results view.
Discussion
The default value is nil.
If the value is nil, the controller uses the default title string.
Availability
- Available in iOS 5.0 and later.
Declared In
UISearchDisplayController.hInstance Methods
initWithSearchBar:contentsController:
Returns a display controller initialized with the given search bar and contents controller.
Parameters
- searchBar
A search bar.
The search bar must not currently be associated with another search display controller.
- viewController
The view controller that manages display of the original contents that are to be searched.
The view controller must not currently be associated with another search display controller.
Return Value
A display controller initialized with the given search bar and contents controller.
Availability
- Available in iOS 3.0 and later.
Declared In
UISearchDisplayController.hsetActive:animated:
Displays or hides the search interface, optionally with animation.
Parameters
- visible
YESto display the search interface if it is not already displayed;NOto hide the search interface if it is currently displayed.- animated;
YESto use animation for a change in visible state, otherwiseNO.
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
- Available in iOS 3.0 and later.
Declared In
UISearchDisplayController.h© 2011 Apple Inc. All Rights Reserved. (Last updated: 2011-10-12)