The error arises because you're passing a nil value to whereKey:nearGeoPoint:
as self.userLocation
is unlikely to be set the first time the view loads. You will want to do two things:
In your
queryForTable
method, check ifself.userLocation
is nil. If it is, return nil. This acts as a no-op and the table won't show any data just yet.- (PFQuery *)queryForTable { if (!self.userLocation) { return nil; } // User's location PFGeoPoint *userGeoPoint = self.userLocation; // Create a query for places PFQuery *query = [PFQuery queryWithClassName:@"MainInfo"]; // Interested in locations near user. [query whereKey:@"geoPoint" nearGeoPoint:userGeoPoint]; // Limit what could be a lot of points. query.limit = 10; // Final list of objects _placesObjects = [query findObjects]; return query; }
In your
geoPointForCurrentLocationInBackground:
completion block, once theself.userLocation
value is set, you will want to call[self loadObjects]
. This will tell thePFQueryTableViewController
to run your query again, and this time aroundself.userLocation
will not be nil, allowing you to construct your original query. Fortunately, you've already performed this step, but I've included it here in case anyone else has the same question.