2016-09-27 9 views
1

私はannotationを地図に載せていますが、ピンをクリックした後、右側にdetail disclosure info buttonがあるはずですので、ボタンをタップしてからコードを追加できます。しかし、私がプロジェクトを実行すると、ピンをクリックすると、info buttonが表示されません。誰でもdisclosure info buttonを追加するコードを提供できますか?MapKit注釈詳細開示情報ボタンを追加する方法は?

私は右側の情報ボタン期待してい:enter image description here

マイコード:

extension ViewController: MKMapView{ 


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



    } 

答えて

5

MKAnnotationViewを作成し、それにボタンを追加します。だから:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 
     if annotation is MKUserLocation { return nil } 

     if let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "") { 
      annotationView.annotation = annotation 
      return annotationView 
     } else { 
      let annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:"") 
      annotationView.isEnabled = true 
      annotationView.canShowCallout = true 

      let btn = UIButton(type: .detailDisclosure) 
      annotationView.rightCalloutAccessoryView = btn 
      return annotationView 
     } 
    } 
+1

ありがとうRashwan、それはうまく動作します! – developermike

+0

@Rob、もう1つの例を更新しました。 –

+0

フィードバックをいただきありがとうございます。 –

関連する問題