gpt4 book ai didi

ios - 在 Segue 之前添加完成处理程序

转载 作者:行者123 更新时间:2023-11-29 01:24:52 25 4
gpt4 key购买 nike

我如何向这段代码添加一个完成处理程序,以确保在我收到“city”或错误之前 View 不会在最后调用该 Segue?

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let longitude = locManager.location?.coordinate.longitude
let latitude = locManager.location?.coordinate.latitude
print(latitude)
let location = CLLocation(latitude: latitude!, longitude: longitude!)
NSUserDefaults.standardUserDefaults().setDouble(longitude!, forKey: "longitude")
NSUserDefaults.standardUserDefaults().setDouble(latitude!, forKey: "latitude")

CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) -> Void in
if error == nil {
let pa = placemarks! as [CLPlacemark]

var placeMark: CLPlacemark!
placeMark = pa[0]

if let city = placeMark.addressDictionary!["City"] as? String {
print(city)
NSUserDefaults.standardUserDefaults().setObject(city, forKey: "city")
}
}
else {
print("Error: " + error!.localizedDescription)
}
})

self.performSegueWithIdentifier("toMain", sender: self)
}

最佳答案

当您没有收到任何错误时,在您的第一个 if 语句中进行调用。

if( error == nil)
{
// make sure value you're getting is correct and save to NSUserDefaults
self.performSegueWithIdentifier("toMain", sender: self)
}
else
{
// handle the error
}

关于ios - 在 Segue 之前添加完成处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34125085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com