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;
The use of Uisearchdisplaycontroller requires:
- Provides the source of data for the search results table-searchresultsdatasource
- Agent searchresultsdelegate for search results table
- The proxy delegate of the Uisearchdisplaycontroller controller, which corresponds to the beginning and end of the search event and the display of the Hidden interface; (This agent knows the change and search scope of the search string.) So the result table can (self-actively) import again)
- Searchbar's agent (about Uisearchbar Agent previous article has been explained)
It is common to initialize Uisearchdisplaycontroller 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 infer 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 (hide) state, default value is no, direct set no animation. With setActive:animated: settings There will be animations
@property (nonatomic, assign) id< Uisearchdisplaydelegate> Delegate
Agent
@property (nonatomic, assign) BOOL Displayssearchbarinnavigationbar
Specify Navigationbar to include 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 > Searchresultsdatasource
Show data sources for search results
@property (nonatomic, assign) id< uitableviewdelegate> searchresultsdelegate
proxy for table displayed by search results
@property (Nonatomic, readonly) uitableview
search results show Table
@property (nonatomic, copy) nsstring *searchresultstitle
title of search results View
-(ID) Initwithsearchbar: ( uisearchbar *) searchbar contentscontroller: ( uiviewcontroller *) viewcontroller
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