0

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

1 Answer 1

1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.