Ios 韩元';不要在地图上加载

Ios 韩元';不要在地图上加载,ios,swift,annotations,mapkit,cloudkit,Ios,Swift,Annotations,Mapkit,Cloudkit,一段时间以来,我一直试图在地图上找到注释的方向。我最近发现了如何做到这一点,但现在并不是我所有的注释都会显示在地图上,只有一个会显示。我正在使用Cloudkit中的公共数据库来存储我的所有用户信息。自从我将变量annotation=MKPointAnnotation()用于整个视图控制器以来,并不是所有的注释都显示在地图上 这就是我获得方向的方式: let annotation = MKPointAnnotation() @IBAction func getDirections(_ sende

一段时间以来,我一直试图在地图上找到注释的方向。我最近发现了如何做到这一点,但现在并不是我所有的注释都会显示在地图上,只有一个会显示。我正在使用
Cloudkit
中的公共数据库来存储我的所有用户信息。自从我将变量
annotation=MKPointAnnotation()
用于整个视图控制器以来,并不是所有的注释都显示在地图上

这就是我获得方向的方式:

let annotation = MKPointAnnotation()

@IBAction func getDirections(_ sender: Any) {
    let view = annotation.coordinate        
    print("Annotation: \(String(describing: view ))")
    let currentLocMapItem = MKMapItem.forCurrentLocation()
    let selectedPlacemark = MKPlacemark(coordinate: view, addressDictionary: nil)
    let selectedMapItem = MKMapItem(placemark: selectedPlacemark)
    let mapItems = [selectedMapItem, currentLocMapItem]
    let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
    MKMapItem.openMaps(with: mapItems, launchOptions:launchOptions)
}
以下是我显示注释的方式:

func fetch() {
    let truePredicate = NSPredicate(value: true)
    let eventQuery = CKQuery(recordType: "User", predicate: truePredicate)
    let queryOperation = CKQueryOperation(query: eventQuery)
    queryOperation.recordFetchedBlock = { (record : CKRecord!) in

        self.truck.append(record)

        self.annotation.title = record?["username"] as? String
        self.annotation.subtitle = record?["hours"] as? String
        if let location = record?["location"] as? CLLocation {
            self.annotation.coordinate = location.coordinate
        }

        print("recordFetchedBlock: \(record)")

        self.mapView.addAnnotation(self.annotation)
    }

    queryOperation.queryCompletionBlock = { (cursor, error) in

        print("queryCompletionBlock: \(self.truck)")
    }

    database.add(queryOperation)
}
我现在得到这个错误:

This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes. 

正如@Surjeet所说,在主线程中编写所有UI更改

DispatchQueue.main.async {
    self.mapView.addAnnotation(self.annotation)
}

正如@Surjeet所说,在主线程中编写所有UI更改

DispatchQueue.main.async {
    self.mapView.addAnnotation(self.annotation)
}

该错误显示您正在后台线程中进行UI更改,因为您面临此错误日志。更新您的代码并在主线程中写入所有UI更改。错误显示您正在后台线程中进行UI更改,因为您面临此错误日志。更新您的代码并在主线程中写入所有UI更改。谢谢!我在强调主线程,我把调度队列放错了位置。当我使“let annotation=mkpointannotation()”可用于整个控制器时,我仍然对地图如何仅显示一个注释感到困惑。谢谢!我在强调主线程,我把调度队列放错了位置。当我使“let annotation=mkpointannotation()”可用于整个控制器时,我仍然对地图如何仅显示一个注释感到困惑。