leftCalloutAccessoryViewForAnnotation
에 대한 switch 문을 Mapbox iOS
에 만들려고합니다. 나는 CustomPointAnnotation
클래스와 재사용 식별자를 생성하는 것을 포함하여 다양한 방법을 시도했지만, 그 중 하나를 사용할 수는 없었다.Mapbox iOS SDK에서 switch 문 만들기
결국 나는 아래에 보이는 것을 만들었습니다. 내가 쓰고 싶은 코드가 아닙니다. 모든 입력을 많이 주시면 감사하겠습니다.
func mapView(mapView: MGLMapView, leftCalloutAccessoryViewForAnnotation annotation: MGLAnnotation) -> UIView? {
if (annotation.subtitle! == "Name") {
let imageView = UIImageView(image: UIImage(named: "imageName")!)
self.view.addSubview(imageView)
return imageView
}
if (annotation.subtitle! == "Name2"){
let imageView = UIImageView(image: UIImage(named: "imageName2")!)
self.view.addSubview(imageView)
return imageView
}
if (annotation.subtitle! == "Name3"){
let imageView = UIImageView(image: UIImage(named: "imageName3")!)
self.view.addSubview(imageView)
return imageView
}
return nil
}
주석
for location in locations {let annotation = MGLPointAnnotation()
let coordinate = CLLocationCoordinate2DMake(location.latitude, location.longitude);
annotation.coordinate = coordinate
annotation.title = location.title
annotation.subtitle = location.subtitle
annotations.append(annotation)
mapView.delegate = self
mapView.addAnnotations(annotations)
위의 방법을 구현 한 후에도 계속해서 다음과 같은 오류가 발생합니다. " 'String'형식의 식 패턴이 'String'유형의 값과 일치하지 않습니다. Mapbox에서지도를 채우기위한 주석 정보를 포함하도록 원래 질문을 수정했습니다. –
오류가 발생하면 제대로 구현하지 못했습니다. 'switch' 문이 옵션 값을 비 선택적 값과 비교할 수 없기 때문에 발생하는 오류입니다. 위의 대답에서'annotation.subtitle'의 값은'if let' 문과의 선택적 바인딩을 통해 non-optional 값이나 nil로 변환됩니다. – xoudini