1
Mein Code zeigt nicht den Titel oder Untertitel der einzelnen Pins an. Die Pins erscheinen auf ihren Koordinaten. Beim Klicken auf die Pins erscheint jedoch nichts. Ich möchte nur, dass die Pins unterschiedliche Farben haben und wenn sie angeklickt werden, zeigen sie eine Nachricht an.mapKit keine Annotation anzeigen
import UIKit
import MapKit
class MyPointAnnotation : MKPointAnnotation {
var pinTintColor: UIColor?
}
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var jmap: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
jmap.delegate = self
let hello = MyPointAnnotation()
hello.coordinate = CLLocationCoordinate2D(latitude: 40, longitude: -73)
hello.title = "My Shop"
hello.subtitle = "its cool"
hello.pinTintColor = .red
let hellox = MyPointAnnotation()
hellox.coordinate = CLLocationCoordinate2D(latitude: 34, longitude: -72)
hellox.title = "NOW"
hellox.title = "JUdo"
hellox.pinTintColor = .blue
jmap.addAnnotation(hello)
jmap.addAnnotation(hellox)
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "myAnnotation") as? MKPinAnnotationView
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myAnnotation")
} else {
annotationView?.annotation = annotation
}
if let annotation = annotation as? MyPointAnnotation {
annotationView?.pinTintColor = annotation.pinTintColor
}
return annotationView
}}
in zurückzukehren, welche Funktion setze ich, dass in –
@sillymilly - Offensichtlich ist Grifas über Ihre 'mapView sprechen. (_: ViewFor:)'. (Das ist die einzige Funktion, bei der Sie 'annotationView' zurückgeben.) – Rob