1
私は私のクラスでtintColorする機能を持っている:tintColor - ランダムな色、なぜですか?
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
}
}
また、私はこの拡張機能を持っている:
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
}
}
私は10秒ごとのMapViewの配列と私のデータをロードし、このようにそれを提示:
func mapView() {
map.layoutMargins = UIEdgeInsets(top: 30, left: 30, bottom: 30, right: 30)
map.showAnnotations(markersArrayFiltered!, animated: true)
}
エラー: - たびに私は新しいデータをロードする際に、ピンの私の色が異なっているが、私のDAT aは変わらない。
私が間違って何をしたのですか?
ありがとうございました!今はすべてが正常に動作します。今私はmapKitについてもっと知っている=) –