2016-09-27 3 views
1

지도에 annotation을 붙이고 핀을 클릭 한 후 오른쪽에 detail disclosure info button이 있어야합니다. 버튼을 누른 후 코드를 추가 할 수 있습니다. 그러나 프로젝트를 실행할 때 핀을 클릭하면 info button이 나타나지 않습니다. 누구든지 disclosure info button을 추가하는 코드를 제공 할 수 있습니까?MapKit annotation 정보 공개 정보 버튼을 추가하는 방법은 무엇입니까?

나는 오른쪽의 정보 버튼을 기대하고있다 : 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, 다른 예를 업데이트했습니다. –

+0

의견을 보내 주셔서 감사합니다. –