gpt4 book ai didi

ios - BAD_EXC_ACCESS 用于在释放时尝试加载 View Controller

转载 作者:行者123 更新时间:2023-11-28 16:13:37 25 4
gpt4 key购买 nike

我在线收到 BAD_EXC_ACCESS。原因是“不允许在释放 View Controller 时尝试加载它的 View ,这可能会导致未定义的行为”。

func drawLocations(loc: CLLocation)
{
let center = CLLocationCoordinate2D(latitude: loc.coordinate.latitude, longitude: loc.coordinate.longitude)
let lat: CLLocationDegrees = center.latitude
let long: CLLocationDegrees = center.longitude
var points = [CLLocationCoordinate2DMake(lat,long),CLLocationCoordinate2DMake(lat,long),CLLocationCoordinate2DMake(lat,long),CLLocationCoordinate2DMake(lat,long)]
let polygon = MKPolygon(coordinates: &points, count: points.count)
mapView.addOverlay(polygon)//where I get error
}
func loadLocation(completion: (error:NSError?, records:[CKRecord]?) -> Void)
{
let query = CKQuery(recordType: "Location", predicate: NSPredicate(value: true))
CKContainer.defaultContainer().publicCloudDatabase.performQuery(query, inZoneWithID: nil){
(records, error) in
if error != nil {
print("error fetching locations: \(error)")
completion(error: error, records: nil)
} else {
print("found locations: \(records)")
print("found locations")
completion(error: nil, records: records)
guard let records = records else {
return
}
for(var i = 0; i<records.count; i += 1)
{
self.drawLocations(records[i]["location"] as! CLLocation)//where I call function
}
}
}
}

最佳答案

performQuery的完成 block “必须能够在应用程序的任何线程上运行”(如文档中所述)。你打电话addOverlay这是一个 UI 函数,在主队列上调用了很多。您需要将此方法分派(dispatch)到主队列。

旁注,与问题无关:for(var i = 0; i<records.count; i += 1)最好写成 for record in records . C 风格语法已弃用。

关于ios - BAD_EXC_ACCESS 用于在释放时尝试加载 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39321935/

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