我的应用程序有一个表视图,其加载速度比cllocationmanager实例初始化(至少这是我的怀疑),并且在运行时cllocation的前几秒内返回零的纬度和纬度。我该怎么做才能避免这个问题?
答案 0 :(得分:1)
好的,首先加载一个空表,然后在locationManager委托中放置位置验证检查,一旦该位置有效,重新加载tableview。这是一个简单的例子:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let newLocation = locations.last
let timeDiff = newLocation?.timestamp.timeIntervalSinceNow
if timeDiff < 5 && (newLocation?.horizontalAccuracy)!<=self.accuracyNeeded{
//stop updating location & heading
self.locationManager?.stopUpdatingLocation()
//set currentUserLocation
Model.sharedInstance.currentUserLocation=newLocation?.coordinate
//Update tableview here
//remove delegate
self.locationManager?.delegate = nil
}
}