I have created a custom TableViewCell
and currently have a button placed in the cell. When the button is pressed, In the tableviewcell.swift
file,
You could subclass UIButton
in your cell with a property for its row.
class MyButton: UIButton {
var row: Int?
}
Then when you set up your table view, in the cellForRowAtIndexPath
method, you set the row
property:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// ...
cell.button.row = indexPath.row
// ...
}
This way when the action fires, you can get the correct row:
@IBAction func employeeAtLunch(sender: MyButton) {
if let row = sender.row {
// access the row
}
}