0

I'm in trouble with a stupid error. When I run the application my segue work twice. I have a tableview with a lot of sections and rows and when the user click on a row I want to perform the segue and programmatically change a text view in the destination view. When I run the program and I click on the tableview the segue works twice. What's the problem?

Here is my code for the segue:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("section: \(indexPath.section)")
        categoriacliccata = indexPath.section
        print("row: \(indexPath.row)")
        rowCliccata = indexPath.row
        performSegue(withIdentifier: "segue_testo", sender: self)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if (segue.identifier == "segue_testo") {
            let secondVC: TextView_Controller = segue.destination as! TextView_Controller
            secondVC.recivedCategoria = categoriacliccata
            secondVC.recivedRow = rowCliccata
        }
    }

enter image description here

Khushbu
  • 2,342
  • 15
  • 18
Twing90
  • 407
  • 2
  • 5
  • 15

1 Answers1

2

Make the segue from the VC itself not from the cell as making it from cell runs code linked in IB and code you wrote in didSelectRow

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87