0

我正在使用PFQueryTableViewControllerUISearchBar。我没有使用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;
 }
4

1 回答 1

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;
}

你好你不能通过变量来管理这个你只是在下面显示我的代码

我认为这段代码对你很有帮助......

于 2015-05-14T13:51:38.883 回答