小编Tim*_*Tim的帖子

未调用MKMapView MKPointAnnotation tap事件

我正在使用带有MKPointAnnotation的MKMapView(正确设置委托).在后台线程上调用的此方法中生成注释.

func updateMapAnnotations() {
    for var i = 0; i < DataManager.getStationList().count; i++ {
        var s = DataManager.getStationList()[i] as Station
        var annotation = MKPointAnnotation()
        annotation.setCoordinate(CLLocationCoordinate2D(latitude: s.latitude, longitude: s.longitude))
        annotation.title = "\(s.id)"
        dispatch_async(dispatch_get_main_queue(), {
            self.mapView.addAnnotation(annotation)
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

annotationViews在这里生成:

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
    if (annotation is MKUserLocation) {
        return nil
    }

    let reuseId = "StationAnnotation"

    let annoStation = DataManager.getStationById(annotation.title!.toInt()!)

    var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
    if anView == nil {

        anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        let base …
Run Code Online (Sandbox Code Playgroud)

mkmapview mkannotationview ios mkpointannotation swift

3
推荐指数
1
解决办法
2388
查看次数