user1469734 user1469734 - 5 months ago 26
Swift Question

IndexPath Swift TableView clicked column

With the following code I get the indexPath of the clicked button in the tableview:

@IBAction func btnClick(_ sender: UIButton) {
let hitPoint = sender.convert(, to: self.tableView)
if let indexPath = self.tableView.indexPathForRow(at: hitPoint){

The first print is
[3, 0]
when I clicked on the 3th row I get the
, but I need the other value. The
in this case.

Answer Source

indexPath returns [section, row].

If you want to access section (the thing you referred to as column ) , use indexPath.section