I'm trying to pass 1 variable to another view controller and then another view controller.
var selectedPlace = Place {
name = Daniel Webster Highway;
country = United States;
lat = 42.72073329999999;
lon = -71.44301460000001;
}
When I select on a cell, I have access to a variable selectedPlace
I want to pass it on to my PlaceDetailVC and also MapVC.
For some reasons, I can't make that happen.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationVC = segue.destination as! PlaceDetailVC
if let indexPath = tableView.indexPathForSelectedRow {
destinationVC.selectedPlace = (places?[indexPath.row])!
destinationVC.selectedTrip = selectedTrip!
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toMap" {
let destinationVC = segue.destination as! MapVC
if let indexPath = placesTable.indexPathForSelectedRow {
destinationVC.selectedPlace = selectedPlace
}
}
}
I also try
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationVC = segue.destination as! MapVC
if let indexPath = placesTable.indexPathForSelectedRow {
destinationVC.selectedPlace = selectedPlace
}
}
print(selectedPlace,"<<<<<<")
I kept getting
Any hints on what I did wrong ?
No need to check indexPath if the segue "toMap" is called by the nav button
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toMap" {
let destinationVC = segue.destination as! MapVC
destinationVC.selectedPlace = selectedPlace
/*
if let indexPath = placesTable.indexPathForSelectedRow {
destinationVC.selectedPlace = selectedPlace
}*/
}
}