주석을 사용하여 간단한지도를 만들려고합니다.하지만 실행하려고하면 detailCalloutAccessoryView의 이미지는 동일하지만 두 개의 다른 이미지를 넣을 것입니다. 어떻게 했습니까? 이 일이 일어날까요? 아니면 누구든지이 일을하는 더 좋은 방법이 있을까요?신속한 mapkit 주석이 같은 CalloutAccessoryView 이미지를 반복합니다.
var tripspot:[tripSpot] = [
tripSpot(title: "1", coordinate: CLLocationCoordinate2DMake(24.149062, 120.684891), location: "台中市北區一中街", type: "rare",cllocation:CLLocation(latitude: 24.181143, longitude: 120.593158),image : "025"),
tripSpot(title: "2", coordinate: CLLocationCoordinate2DMake(24.180407, 120.645086), location:"台中逢甲", type: "rare",cllocation:CLLocation(latitude: 24.180407, longitude: 120.645086),image : "007")]
// Build LocationManager
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// set data
setupData()
}
func setupData(){
for aSpot in tripspot {
//set annotation
let coordinate = aSpot.coordinate
let title = aSpot.title
let type = aSpot.type
//set annotation
let tripSpotAnnotation = MKPointAnnotation()
tripSpotAnnotation.coordinate = coordinate
tripSpotAnnotation.title = title
tripSpotAnnotation.subtitle = type
mapView.addAnnotations([tripSpotAnnotation])
}
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?
{
if annotation.isKindOfClass(MKUserLocation)
{
return nil
}
var view = mapView.dequeueReusableAnnotationViewWithIdentifier("annotationIdentifier")as? MKPinAnnotationView
if view == nil
{
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "annotationIdentifier")
view?.canShowCallout = true
view?.sizeToFit()
}
else{
view!.annotation = annotation
}
for aSpot in tripspot{
// set pinview
let detailCalloutAccessoryView = UIImageView(frame: CGRectMake(0, 0, 53, 53))
detailCalloutAccessoryView.image = UIImage(named: aSpot.image!)
view?.detailCalloutAccessoryView = detailCalloutAccessoryView
view?.pinTintColor = pinColor(annotation.subtitle!!)
}
return view
}
어떤 조언을 주셔서 감사합니다.
관련 없음, 나는 당신이 Cocoa 명명 규칙을 따르고'class'와'struct' 형에 대문자로 시작하는 이름을 주도록 제안합니다 (예 :'TripSpot'). 형식을 참조 할 때와 해당 형식의 인스턴스를 참조 할 때 더욱 명확합니다. – Rob