UisearchdisplaycontrolleR and Uisearchbar are used together to manage the display of Uisearchbar and search results. Uisearchdisplaycontroller provides a tableview that displays search results to cover the original controller's view;
Using Uisearchdisplaycontroller requires:
- Provides the source of data for the search results table-searchresultsdatasource
- Agent searchresultsdelegate for search results table
- Uisearchdisplaycontroller Controller Agent delegate, the corresponding search event start end and display hidden interface, (this agent knows the search string changes and search scope, so the result table can (auto) re-import)
- Searchbar's agent (about Uisearchbar Agent previous article has been explained)
Usually the Uisearchdisplaycontroller is initialized in UITableView to show a list;
Searchcontroller = [[Uisearchdisplaycontroller alloc] initwithsearchbar:searchbar contentscontroller:self]; Searchcontroller.delegate = Self;searchcontroller.searchresultsdatasource = self; Searchcontroller.searchresultsdelegate = self;
In the Tabelview proxy method, you need to determine which table (Uitableviewcontroller has Self.tableview Uisearchdisplaycontroller. Searchresultstableview)
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section { if (TableView = = Self.tableview) { return ...; } If necessary (if the data source for other table views), //Check whether TableView is Searchcontroller.sea Rchresultstableview. return ...;}
A uiviewcontroller and a uisearchbar have only one uisearchdisplaycontroller;
You can use Searchdisplaycontroller in Navigationbar after iOS7, By configuring the Displayssearchbarinnavigationbar and Navigationitem attributes in the Uisearchdisplaycontroller;
Related properties and methods
@property (nonatomic, getter=isactive) BOOL active
Show (hidden) state, default value is no, direct set no animation, with setActive:animated:
settings will be animated
@property (nonatomic, assign) id< Uisearchdisplaydelegate> Delegate
Agent
@property (nonatomic, assign) BOOL Displayssearchbarinnavigationbar
Specifies that Navigationbar contains a searchbar
@property (nonatomic, ReadOnly) Uinavigationitem *navigationitem
The read-only attribute represents the Searchdisplaycontroller in the Navigationbar of the navigation controller;
@property (nonatomic, ReadOnly) Uisearchbar *searchbar
Uisearchbar in the Uisearchdisplaycontroller;
@property (nonatomic, ReadOnly) Uiviewcontroller *searchcontentscontroller
This property manages what is searched for
@property (Nonatomic, assign) id< uitableviewdatasource
Show data sources for search results
@property (nonatomic, assign) id< uitableviewdelegate> searchresultsdelegate
proxy for table displayed by search results
@property (Nonatomic, readonly) uitableview * Searchresultstableview
search results show Table
@property (nonatomic, copy) nsstring *searchresultstitle
title of search results View
-(ID) InitWithSearchBar: ( uisearchbar *) searchbar Contentscontroller: ( Uiviewcontroller *) viewCo Ntroller
Initialize controller specifies associated search and view controller
-(void) SetActive: (BOOL) Visible animated: (BOOL) animated
Show or hide the search view
Content from Apple Docs
IOS Uisearchdisplaycontroller Learning Notes