2017-12-24 15 views
-1

아래 모든 주석을 제거하는 방법,하지만 내가 필요를 제거하는 4 빠른 내가 시도은 하나의 주석 (모든)

self.mapView.annotations.forEach { 
    if !($0 is MKUserLocation) { 
     self.mapView.removeAnnotation($0) 
    } 
} 

또는

func removeAllAnnotations() { 
    let annotations = mapView.annotations.filter { 
     $0 !== self.mapView.userLocation 
    } 
    mapView.removeAnnotations(annotations) 
} 

특정 주석을 제거하는 것입니다 며칠 전에 도움을받지 못하면서 누군가가 조언을 해줄 수 있었습니까?

array = [{annotationID: 1234, anotationTitle: "myLocation"}, 
     {annotationID: 321, anotationTitle: "locationMy"}] 

다음과 같이 당신에게

주석 배열을 귀찮게 죄송 나는

{annotationID: 1234, anotationTitle: "myLocation"} 

어떻게 제거 싶어?

+0

주석에 식별할만한 것이 있습니까? –

+0

예, NSDictionary 형식입니다. 모든 주석은 배열에 있습니다 –

+0

이 코드에 대한 더 많은 컨텍스트를 보여주십시오. –

답변

0

몇 가지 방법이 있습니다. 제목을 식별 할 수 있으면 다음 코드를 시도하십시오.

func removeSpecificAnnotation() { 
    for annotation in self.mapView.annotations { 
     if let title = annotation.title, title == "myLocation" { 
      self.mapView.removeAnnotation(annotation) 
     } 
    } 
} 
+0

아직 테스트하지는 못했지만 나에게 의미있는 소리가 들려왔다. –

+0

나는 이드를 사용할지도 모른다. –