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