extension TravelInfoViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard let annotation = annotation as? stopInfo else {return nil}
let identifier = "stopInfo"
var view : MKMarkerAnnotationView
// 1
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView {
dequeuedView.annotation = annotation
view = dequeuedView
} else { //2
view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
}
return view
}
}
위와 같은 코드로 변경할 수 있습니다
간단하게 말하면 UITableCell 을 사용하는 방법과 거의 비슷하다고 할 수 있습니다
1번은 아직 클릭하지 않았을 때를 의미
2번은 클릭했을 때를 말합니다