0

I have a UISlider whose value varies between -31 and 0. The initial value is 0. I can't understand why when I change the value of my slider (taking it for example 0,-1, -2, -3, ..., -20), this value is not reported correctly inside the func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?, but rather always remains 0. How can I report every single change of the slider value within that function?

class MapViewController: UIViewController,MKMapViewDelegate,CLLocationManagerDelegate,SCSEarthquakesHandler,SCSPublicSeismometersHandler
{
    @IBOutlet weak var mapView: MKMapView!
    @IBOutlet var slider: UISlider!

    @IBAction func changeSliderValue(_ sender: Any){
        let newDate = calendar.date(byAdding: .day, value: slider, to:rigthNow) 
        dateFormatter.dateStyle = .medium // "MM/GG/AAAA"
        labelTime.text = "\(dateFormatter.string(from: newDate!))"
    }

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
        print(Int(slider.value))
        //some other piece of code that is not needed now for this problem
    }
}
  • You need to update the annotation, e.g. remove it and add it again to the map. See https://stackoverflow.com/questions/10774002/force-mkmapview-viewforannotation-to-update/11643912 – Andreas Oetjen Oct 15 '20 at 19:35
  • Why are you deleting and reposting [the same question](https://stackoverflow.com/questions/64372386/uislider-value-into-mapview-function-swift?noredirect=1#comment113829679_64372386) only hours later? – Joakim Danielson Oct 15 '20 at 19:39

0 Answers0