I want to pass different arrays from one ViewController to another based on which row is selected.
How can I get the index for selected row?
I have tried this, but it does not work:
let toDetailVCSegue = "ToDetailVCSegue"
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: toDetailVCSegue, sender: indexPath)
}
func prepare(for segue: UIStoryboardSegue, sender: IndexPath?)
{
if segue.identifier == toDetailVCSegue
{
let destination = segue.destination as! DetailViewController
if let indexPath = tableView.indexPathForSelectedRow{
if indexPath.row == 0 {
destination.itemArray = namesArray
print("test")
}
if indexPath.row == 1 {
destination.itemArray = scoresArray
}
if indexPath.row == 2 {
destination.itemArray = timesArray
}
if indexPath.row == 3 {
destination.itemArray = completedArray
}
}
}
}