我有一个视图控制器上的UI标签和一个位于nsobject上的字符串(准确度)。我想把字符串放在不断更新的uilabel上,因为当你打印字符串(精度为)时,它会更新。有人能帮我吗 ?由于如何将UILabel连接到其他类
class Home: UIViewController {
@IBOutlet weak var lbl_accuracy: UILabel!
}
class PBLocation: NSObject, CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if CLLocationManager.locationServicesEnabled() {
switch(CLLocationManager.authorizationStatus()) {
case .notDetermined, .restricted, .denied:
print("No access")
case .authorizedAlways, .authorizedWhenInUse:
let accuracy = String(format: "%.4f", (locations.last?.horizontalAccuracy)!)
print("accuracy = \(accuracy)")
}
} else {
print("Location services are not enabled")
}
}
}
使用您的viewController作为CLLocationManagerDelegate那么你可以直接改变值'self.lbl_accuracy.text = accuracy'在行,你正在打印'打印(“精度= \(精度)”)' –