UISearchbar和PFQueryTableViewController

时间:2015-05-12 14:32:29

标签: ios uisearchbar pfquery pfquerytableviewcontrolle

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

1 个答案:

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

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

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