我正在使用PFQueryTableViewController
和UISearchBar
。我没有使用UISearchBarDisplayController
。基础查询仅在我以小写或大写形式写入搜索字符串时进行搜索。我想两者都用。无论是小写还是大写,它都会搜索。这是我的一段代码。
-(PFQuery *)queryForTable
{
PFQuery *query;
if (self.canSearch == 0) {
query = [PFQuery queryWithClassName:@"_User"];
} else {
query = [PFQuery queryWithClassName:@"_User"];
//This is searchbar text.
//NSString *searchThis = [_searchbar.text upercaseString];
NSString *searchThis = [_searchbar.text lowercaseString];
[query whereKey:@"username" containsString:searchThis];
}
[query orderByAscending:@"username"];
// If Pull To Refresh is enabled, query against the network by default.
if (self.pullToRefreshEnabled) {
query.cachePolicy = kPFCachePolicyNetworkOnly;
}
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
return query;
}
答案 0 :(得分:0)
- (PFQuery *)queryForTable {
// Use cached facebook friend ids
PFQuery *query = [PFUser query];
[query whereKey:@"Useridentifier" matchesRegex:searchBar_User.text];
PFQuery *query1 = [PFUser query];
[query1 whereKey:@"displayName" matchesRegex:searchBar_User.text];
PFQuery *userQuery = [PFQuery orQueryWithSubqueries:@[query, query1]];
userQuery.cachePolicy = kPFCachePolicyNetworkOnly;
if (self.objects.count == 0)
{
userQuery.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[userQuery orderByAscending:kPAPUserDisplayNameKey];
return userQuery;
return query;
}
你好,你不能通过变量管理这个你只需在下面显示我的代码
我认为这段代码对你很有用......