Ich habe eine Funktion für tintColor in meiner Klasse:tintColor - zufällige Farbe, warum?
func pinColor() -> UIColor {
switch status.text! {
case "online":
return UIColor(red: 46/255, green: 204/255, blue: 113/255, alpha: 1.0)
default:
return UIColor.red
}
}
Auch ich habe diese Erweiterung:
extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Marker {
let identifier = "pin"
var view: MKPinAnnotationView
if let dequeuedView = map.dequeueReusableAnnotationView(withIdentifier: identifier)
as? MKPinAnnotationView {
dequeuedView.annotation = annotation
view = dequeuedView
} else {
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure) as UIView
view.pinTintColor = annotation.pinColor()
}
return view
}
return nil
}
}
ich für mapView meine Daten mit Array laden alle 10 Sekunden und es wie folgt vorstellen:
func mapView() {
map.layoutMargins = UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30)
map.showAnnotations(markersArrayFiltered!, animated: true)
}
Fehler: - jedes Mal, wenn ich neue Daten geladen werden, meine Farben der Pins sind unterschiedlich, aber mein dat a ändert sich nicht.
Was habe ich falsch gemacht?
Vielen Dank! Jetzt funktioniert alles wie es soll. Jetzt weiß ich über mapKit mehr =) –