I have a PFQueryTableViewController set up to retreive a list of objects satisfying a set of basic constraints when the view is loaded Below is the method that implements the query.
- (PFQuery *)queryForTable {
//The base query.
self.query = [PFQuery queryWithClassName:self.parseClassName];
[self.query includeKey:@"photos"];
[self.query includeKey:@"user"];
[self.query orderByDescending:@"createdAt"];
[self.query whereKey:@"ordered" equalTo:[NSNumber numberWithBool:false]];
// [query whereKey:@"location" nearGeoPoint:self.currentLocation withinKilometers:32.2];
// If Pull To Refresh is enabled, query against the network by default.
if (self.pullToRefreshEnabled) {
self.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) {
self.query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
return self.query;
}
However, I also want to give the user the option to filter the results. The code I am using to try and filter is not working, as the list of objects doesn't change.
[self clear];
[self.query whereKey:@"cuisine" equalTo:cuisine.text];
[self loadObjects];
These instructions are embedded in a UIAlertController
that contains a UITextField
called cuisine
Why isn't the filter going through?
Thanks, Siddharth
Every time you execute loadObjects it will get a new query via queryForTable:
Try this:
-(void)search
{
[self clear];
//include this if you want to clear the query before applying the new filter
self.query = [self startingQuery];
[self.query whereKey:@"cuisine" equalTo:cuisine.text];
[self loadObjects];
}
-(PFQuery *)query
{
if (!_query) _query = [self startingQuery];
return _query;
}
- (PFQuery *)queryForTable {
return self.query;
}
-(PFQuery *)startingQuery
{
//The base query.
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query includeKey:@"photos"];
[query includeKey:@"user"];
[query orderByDescending:@"createdAt"];
[query whereKey:@"ordered" equalTo:[NSNumber numberWithBool:false]];
// [query whereKey:@"location" nearGeoPoint:self.currentLocation withinKilometers:32.2];
// 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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.