-1

After the first tap the row gets highlighted (gray background), and then I've to tap any of the following rows to perform the segue.

I do get the right readings, for instance indexPath.row returns 0 if I tapped the first row initially to begin with and then it doesn't matter which row I tap next to make it work.

It's a subclass of UITableViewController

override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
    // delegate?.onSelect(users![indexPath.row])
    print("selected %d", indexPath.row)
    self.performSegue(withIdentifier: "segueToUserForm", sender: users![indexPath.row])
}

I did erase all content and settings from the hardware menu of the simulator.

Developer
  • 924
  • 3
  • 14
  • 30

2 Answers2

2

It seems you are using didDeselectRowAt. This means that this code is called not after the tableCell is selected on the first tap, but when it is deselected on the second tap. Therefore, your code should not be this:

    override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        // delegate?.onSelect(users![indexPath.row])
        print("selected %d", indexPath.row)
        self.performSegue(withIdentifier: "segueToUserForm", sender: users![indexPath.row])
    }

But this:

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        // delegate?.onSelect(users![indexPath.row])
        print("selected %d", indexPath.row)
        self.performSegue(withIdentifier: "segueToUserForm", sender: users![indexPath.row])
    }

Of course, didDeselectRowAt is useful in specific situations, however, it seems that it is not useful in your case. In short, replace didDeselctRowAt to didSelectRowAt.

0

You should use didSelectRowAt not didDeselectRowAt to perform the segue. didDeselectRowAt is triggering in second tap because the 1st tap triggers didSelectRowAt.

  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
       //Your Code
    }
Bishow Gurung
  • 1,962
  • 12
  • 15