swiftuitableviewuitableviewrowaction

UITableView row selection and tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)


I do row selection in my code

tbvCounters.selectRow(at: counterIndexPath, animated: true, scrollPosition: .middle)

and I assume that protocol method

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

should be triggered but it`s not. It works fine when I tap the row of UITableView as user action. How I could simulate user tapping ti trigger "didSelectRowAt" method?


Solution

  • selectRow doesn't trigger didSelectRowAt , but you can trigger with

    tbvCounters.selectRow(at: counterIndexPath, animated: true, scrollPosition: .middle)
    self.tableView(self.tbvCounters, didSelectRowAt: counterIndexPath)