Hier ist mein Code. Ich habe alle verfügbaren Lösungen ausprobiert, aber ich bin nicht in der Lage, das Bild, das ich wünsche, anstelle des Standard-Anmerkungs-roten Stiftes in meinen Code zu stellen.Swift2 iOS9 - wie benutzerdefinierte Bild anstelle von Standard-Anmerkungs rote Pin in meinem Code erhalten
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
var location = CLLocationCoordinate2DMake(18.956449, 72.810597)
var span = MKCoordinateSpanMake(0.009, 0.009)
var region = MKCoordinateRegion(center: location, span: span)
map.setRegion(region, animated: true)
var annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = "Wilson College"
annotation.subtitle = "Commerce College"
map.addAnnotation(annotation)
print("showing on map")
mapView(map, viewForAnnotation: annotation)
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "MyPin"
print("inside viewForAnnotation")
if annotation.isKindOfClass(MKUserLocation) {
return nil
}
let detailButton: UIButton = UIButton(type: UIButtonType.DetailDisclosure)
// Reuse the annotation if possible
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
if annotationView == nil
{
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "pin")
annotationView!.canShowCallout = true
annotationView!.image = UIImage(named: "VRtest.png")
annotationView!.rightCalloutAccessoryView = detailButton
print("editing annotation")
}
else
{
annotationView!.annotation = annotation
}
return annotationView
}
Jede Hilfe ist willkommen. danke
** NIE ** Anruf 'viewForAnnotation' alleine. Die Delegate-Methode wird vom Framework aufgerufen. – vadian
PLZ Führer, ich bin ein Amateur. Ich habe einige Druckanweisungen angegeben, um den Codefluss zu verstehen. mit dem aktuellen Code, bekomme ich diese Anweisungen in der Ausgabebox, "auf der Karte anzeigen", "in ViewForAnnotation", "Bearbeitung von Annotation", und wenn ich die Zeile entfernen - mapView (map, viewForAnnotation: Annotation), dann bekomme ich das Aussage - nur auf der Karte anzeigen. – SagarWadekar