UISearchbar 和 PFQueryTableViewController

UISearchbar and PFQueryTableViewController

我正在使用 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;
 }
- (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;
}

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

我觉得这段代码对你很有帮助...