【发布时间】:2015-01-11 09:32:22
【问题描述】:
位置管理器需要一段时间来查询一个包含 10000 行的类(在 Parse 中)。 我试图阻止用户在查询完成之前选择一行(在 tableViewController 中)。 在允许选择之前强制用户等待查询完成的最佳方式是什么?
查询加载数据:
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)")
}
})
}
其他信息:
程序使用带有segues的didSelectRowAtIndex:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 0 {
self.performSegueWithIdentifier("toQ2", sender: self)
} else {
self.performSegueWithIdentifier("toQ1", sender: self)
}
viewDidLoad 调用 locationManager:
override func viewDidLoad() {
self.locationManager.delegate = self //location manager start
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}
【问题讨论】:
标签: objective-c swift asynchronous parse-platform