0

I've double-checked that my identifier is spelled correctly in the storyboard and that the segue is pointed in the right direction, but I keep receiving this error. Could someone take a look at my code to see if I'm missing something?

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let selectedData = tableData[indexPath.row]
        tableView.deselectRow(at: indexPath, animated: true)
        performSegue(withIdentifier: "goToDetail", sender: selectedData)
    }
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let destination = segue.destination as? DetailViewController {
            destination.vocab.text = sender as? String
        }
    }

Edit: enter image description here

heliona203
  • 23
  • 3

2 Answers2

0

segue can be used only with if you have a UINavigationController that will handle the navigation. You performing a segue to UINavigationController. UINavigationController should be at the root of your storyboard.

enter image description here

tuyen le
  • 305
  • 5
  • 11
0

In your didSelectRowAt function change

performSegue(withIdentifier: "goToDetail", sender: selectedData)

To NavigationController Identifier (Note if you do not have identifier already set up in storyboard you will need to do that first)

performSegue(withIdentifier: "goToNavigationConrtoller", sender: selectedData)

And then change the prepareForSegue function to below.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    //check destination for segue is Navigation controller
    if let navVC = segue.destinationViewController as? UINavigationController {
        // get hold of the first viewController.
        if let destination = navVC.viewControllers[0] as? DetailViewController {
            destination.vocab.text = sender as? String
            //all the other code you need
        }
    }
}
chirag90
  • 2,211
  • 1
  • 22
  • 37