Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@clc80
Last active January 30, 2020 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clc80/2b14c99adf0481d0386eddc24af6cf2a to your computer and use it in GitHub Desktop.
Save clc80/2b14c99adf0481d0386eddc24af6cf2a to your computer and use it in GitHub Desktop.
This is the function that makes data passing possible
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//1. Make sure you are using the correct segue
if segue.identifier == "ShowNameSegue" {
//2. Get the instance of your detail view from the segue's destination
//3. Get the index path for the row that the user tapped
if let detailViewController = segue.destination as? NameDetailViewController,
let indexPath = tableView.indexPathForSelectedRow {
//4. Initialize the word with indexPath
let name = names[indexPath.row]
//5. Pass the array to the detail view
detailViewController.name = name
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment