Uisearchbar often use with uitable, so let's introduce Uisearchbar
First look at the structure.
Let's see what the style is.
-
Basic Search bar. Inside???? The search text is used to prompt the user?? Enter query off?? Word, the placeholder property of the search bar can set this hint message
-
With the?? In addition to the search bar for buttons. In?? Into the box?? When you enter text, it will appear later?????? In addition to the button, point???? Except the button can?? Except?? The text in the box
-
has a search bar with the query results button. Show the most?? Search results, shown in setting 4-31, select options under the Shows Search Results button check box, event?? The should be managed by the searchbarresultslistbuttonclicked: method in the Uisearch-bardelegate object;
-
The search bar with the bookmark button. Show user receive?? The list of bookmarks, shown in setting 4-31, select the Shows Bookmarks button check box in the options, event?? The should be managed by the searchbarbookmarkbuttonclicked: method in the Uisearchbardelegate object;
-
with fetch?? The search bar for the button. Show setting 4-31, select the Show Cancel button check box under Options, event?? The should be managed by the searchbarcancel-buttonclicked: method in the Uisearchbardelegate object;
-
With the search bar for scope. Display setting 4-31, select the Shows scope Bar check box under options and you need to set the scope Titles below. When this option is selected, the Search bar appears?? The scope Titles are displayed below. If???? Not at all? Show?? In the search bar?? Got to?? Point is displayed,?? You can include the following code in the Viewdidload method of the View controller:
[Self.searchbar Setshowsscopebar:no];
[Self.searchbar SizeToFit]; Second, the event?? The should be managed by uisearchbardelegate or uisearchdisplaydelegate objects;
Note: The search can use this class Nspredicate specific use method can be in Baidu a bit
Two protocols must be used before use
- Uisearchbardelegate
- Uisearchdisplaydelegate
In the search bar?? Enter query?? Pieces, will?? The searchbar:textdidchange of the Uisearchbardelegate delegate object: Method and Searchdisplaycontroller of the Uisearchdisplaydelegate delegate object: Shouldreloadtableforsearchstring: Method, we implement?? One of them?? OK?? To the basic purpose of the search. Searchdisplaycontroller:shouldreloadtable-forsearchstring: The method of excellent?? Is that you can control whether the table view data source is reloaded. If the search function is implemented using the Searchbar:textdidchange: Method of the Uisearchbardelegate delegate object, we also need to
You call the [TableView Reloaddata] method to reload the table view data yourself.
In this example, the searchdisplaycontroller:shouldreloadtableforsearchstring is implemented: Method,?? The implementation code in the VIEWCONTROLLER.M file is as follows:
-(BOOL) Searchdisplaycontroller: (Uisearchdisplaycontroller *) controller shouldreloadtableforsearchstring: ( NSString *) searchstring{ // if?? Back to Yes???? Table view can be?? Reload return
IOS9 is no longer recommended after the use of Uisearchdisplaycontroller, has been used Uisearchcontroller and in the xcode7.2.1 version, the interface can not be dragged out Uisearchcontroller
Fourth: IOS table Table View search function Uisearchbar