2016-09-04 5 views
1

私はカスタム注釈を作成しようとしています。カスタム注釈クラスを作成しました。ここで私は注釈ビューを設計します。私のViewControllerのviewForAnnotationでクラスを呼び出そうとしています。私はアプリを実行すると、それは私に基本的なビューを表示されます。ここに関数があります。カスタムアノテーションクラスも見たいかどうかを教えてください。viewForAnnotationはnilを返します

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

注釈をマップビューにどのように表示しますか? –

答えて

0

にfuncのMapView(のMapView:MKMapView、viewForAnnotation注釈:MKAnnotation) - > MKAnnotationView?注釈が私のためMKUserLocation { nilの リターン}

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

関連する問題