有人能告诉我为什么我的segue传递旧数据吗?旧的意思是文本“test”被传递,而不是idForPlace的新变量,它首先从API请求中检索它的值。在更改idForPlace的值之后,我是否需要使用完成处理程序或手动准备segue?
...
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
}
...
1条答案
按热度按时间yhuiod9q1#
因为您在
mapView
中有一个要更新的局部变量但在
prepare(for:sender:)
中使用的是为类定义的属性所以删除局部变量并执行