1, Nspredicate
(1) Comparison operators
1. Compare operators >, <, = =, >=, <=,! =
Operators can also use,&& with logical operators, | | , and, OR predicates are case insensitive
Nspredicate *p = [nspredicate predicatewithformat:@ "Age >= && name = ' Week Week '"];
Returns an array of responses based on predicate requirements
Nsarray * personlist = [self.datalist filteredarrayusingpredicate:p];
[Self.datalist Filterusingpredicate:p];
(2) Range operator
In: equals the in operation of SQL, the left expression must appear in the collection specified on the right.
Between: The expression on the left is equal to the value of the right expression or between them, and to the right is a sequence of numbers with two specified upper and lower bounds (number of sequences in the specified order)
Nspredicate * p = [nspredicate predicatewithformat:@ "age between {30,60}"];
Nsarray * personlist = [self.datalist filteredarrayusingpredicate:p];
(3) tail-tracking
Start with XX--beginswith
End With XX--endswith
Nspredicate * p = [nspredicate predicatewithformat:@ "name Beginswith ' big ' | | name ENDSWITH%@", @ "dew"];
Nsarray * personlist = [self.datalist filteredarrayusingpredicate:p];
(4) Include query
Contains contains: The expression on the left contains the expression on the right.
Nspredicate * p = [nspredicate predicatewithformat:@ "%K CONTAINS%@", @ "name", @ "Huan"];
Nspredicate * p = [nspredicate predicatewithformat:@ "%K CONTAINS ' Huan '", @ "name"];
Nsarray * personlist = [self.datalist filteredarrayusingpredicate:p];
(5) Fuzzy query
Like: The expression on the left equals the right expression
* Denotes 0 or more characters
? Represents a character
Nspredicate * p = [nspredicate predicatewithformat:@ "name like ' * Huan * '"];
Nspredicate * p = [nspredicate predicatewithformat:@ "name like ' Huan * '"];
Nsarray * personlist = [self.datalist filteredarrayusingpredicate:p];
(6) Query the string itself
The string itself is queried, and each item in the array is a string in order to query with self
Nsarray * names = @[@ "Big Huan", @ "Week Week", @ "Dew dew", @ "Rice rice", @ "Huan elder brother"];
Nspredicate * p = [Nspredicate predicatewithformat:@ "self = ' great Huan '"];
Nspredicate * p = [nspredicate predicatewithformat:@ "Self CONTAINS%@", @ "Huan"];
Nsarray * personlist = [names Filteredarrayusingpredicate:p];
(7) Regular expression: MATCHES
NSString *pattern = @ "^ ((13[0-9]) | ( 15[^4,\\D]) | (18[0,0-9])) \\d{8}$ ";
Nspredicate * p = [nspredicate predicatewithformat:@ "Self MATCHES%@", pattern];
predicate in which an object is passed in to match a regular expression
BOOL istelnumber = [P evaluatewithobject:@ "118260930"];
if (Istelnumber) {
NSLog (@ "mobile phone number");
} else {
NSLog (@ "Not mobile phone number");
}
2. Uisearchcontroller Search Controller
(1) The first form of
Create a table controller that accepts results and shows
Searchresultviewcontroller * RESULTVC = [[Searchresultviewcontroller alloc] initwithstyle:uitableviewstyleplain];
Creating a Search Controller
Uisearchcontroller * SEARCHVC = [[Uisearchcontroller alloc] INITWITHSEARCHRESULTSCONTROLLER:RESULTVC];
Set up data Update Agent
Searchvc.searchresultsupdater = self;
Use modal view to jump to the search controller
[Self PRESENTVIEWCONTROLLER:SEARCHVC animated:yes completion:nil];
Get the input text through Searchbar
NSString * searchstring = SearchController.searchBar.text;
Filter search Content
[Self updatefiltercontent:searchstring];
Self.resultlist already have the value of the search.
Determine if Searchcontroller exists Searchresultscontroller
if (Searchcontroller.searchresultscontroller) {
Get the Searchresultviewcontroller reference by Searchresultscontroller
Searchresultviewcontroller * SEARCHRESULTVC = (Searchresultviewcontroller *) Searchcontroller.searchresultscontroller;
Assigning a data source to a search results controller
Searchresultvc.searchresults = self.resultlist;
Refresh the search Results Controller table
[Searchresultvc.tableview Reloaddata];
-(void) Updatefiltercontent: (NSString *) searchstring {
[C] Case insensitive
Nspredicate * p = [nspredicate predicatewithformat:@ "self contains[c]%@", searchstring];
Self.resultlist = [Self.datalist filteredarrayusingpredicate:p];
}
(2) The second form of
#warning be sure to set the Uisearchcontroller object as a global variable
Self.tableView.tableHeaderView = Self.searchVC.searchBar;
and place the button response event in the Viewdidload
IOS Verbs explained