Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Segue passes old data

Can someone tell me why my segue passes old data? With old I mean the text "test" gets passed and not the new variable for idForPlace which first retrieves its value from an API request. Do I need to use a completion handler or manually prepare the segue after changing the value of idForPlace?

...
var idForPlace = "test"
    
    @IBOutlet weak var mapView: GMSMapView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        loadingInitialMap()
        
    }
 
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "Fenster1" {
            let destinationVC = segue.destination as? ViewComments
            destinationVC?.idForPlace = idForPlace
        }
    }

    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
        
        if marker.title == nil {
            print("Kein Marker vorhanden")
        } else {
            print("Vorhandene Marker angeklickt")
            ViewController.titelUebertragen = marker.title!
            let data = marker.userData as? [String:String]
            var idForPlace = (data?["id"])!
                        
            let ref = Database.database().reference()
            ref.child("placeID/\(idForPlace)").observeSingleEvent(of: .value, with: { (snapshot) in
                
            print(idForPlace)
            self.performSegue(withIdentifier: "Fenster1", sender: marker)
            
              })

        }
        
        return true
    }
...

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Because you have a local variable in mapView that you update

var idForPlace = (data?["id"])!

but what you use in your prepare(for:sender:) is the property defined for the class

destinationVC?.idForPlace = idForPlace

so remove the local variable and instead do

self.idForPlace = (data?["id"])!
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading