2016-09-04 52 views
1

我試圖做一個自定義註釋。我做了一個自定義註記類,在那裏我設計了註解視圖。我試圖在ViewController的viewForAnnotation中調用這個類。當我運行該應用程序時,它會向我顯示基本視圖。這是功能。讓我知道你是否也想看到自定義註記類。viewForAnnotation返回無

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 


    let reuseIdentifier = "CustomAnnotation" 


    if (annotation.isKindOfClass(CustomAnnotation)) { 
     var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseIdentifier) as! CustomAnnotation! 


     annotationView = CustomAnnotation(annotation: annotation, reuseIdentifier: reuseIdentifier) 

     return annotationView 
    } 
     else { 
      return nil 
    } 

} 
+0

對我來說,它看起來像你混淆了術語'annotation'和'annotationview'。你設置了一個自定義的'annotation',但是嘗試將它用作'annotationview'(參見函數簽名:'MKAnnotation'!='MKAnnotationView')。 –

+0

我必須解決什麼問題? – jonask

+0

你想如何在mapview上顯示你的註解? –

回答

0

FUNC MapView類(MapView類:的MKMapView,viewForAnnotation註解:MKAnnotation) - > MKAnnotationView? { 如果註釋MKUserLocation { 回零 }

let reuseId = "pin" 
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView 
    if pinView == nil { 
     pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
     pinView?.animatesDrop = true 
     pinView?.canShowCallout = false 
     pinView?.draggable = true 
       } 
    else { 
    } 

    return pinView 
} 
+0

自定義註釋是在哪裏進來的? – jonask