我尝试用注释制作一个简单的地图,但是当我尝试运行它时,detailCalloutAccessoryView 的图像是相同的,但我确定我放了两个不同的图像,这是怎么发生的?或者有没有人有更好的方法来做到这一点?
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
}
感谢您的任何建议。