The location manager takes a while to query through a class of 10000 rows (in Parse). I'm trying to prevent the user from selecting a row (in tableViewController) before the query finishes. What is the optimal way to force the user to wait for the query to complete before allowing the selection?
Query to Load Data:
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: { (placemarks, error) -> Void in
if (error != nil) {
println("Error:" + error.localizedDescription)
}
if placemarks.count > 0 {
let pm = placemarks[0] as CLPlacemark
self.displayLocationInfo(pm)
currentLoc = manager.location
currentLocGeoPoint = PFGeoPoint(location:currentLoc)
var query = PFQuery(className:"test10000")
query.whereKey("RestaurantLoc", nearGeoPoint:currentLocGeoPoint, withinMiles:10) //filter by miles
query.limit = 1000 //limit number of results
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if objects != nil {
unfilteredRestaurantArray = objects
} else {
println("error: \(error)")
}
}
} else {
println("error: \(error)")
}
})
}
Additional Info:
The program uses didSelectRowAtIndex with segues:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 0 {
self.performSegueWithIdentifier("toQ2", sender: self)
} else {
self.performSegueWithIdentifier("toQ1", sender: self)
}
viewDidLoad calls the locationManager:
override func viewDidLoad() {
self.locationManager.delegate = self //location manager start
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}