6

I currently have a table with some dynamic rows. When I run the probject the rows display on the screen and even have a press animation but xcode won't let me wire up the table row as an IBAction to its controller. I can't use a segue in this instance, it needs to be like a button press but preferably on the whole table rown I'd rather not insert a button into it. Any help appreciated, thanks!

Evernoob
  • 5,551
  • 8
  • 37
  • 49

2 Answers2

7

You want to override the table:didSelectRowAtIndex function. It is a method on WKInterfaceController.

override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    // Handle row selection
}
hgwhittle
  • 9,316
  • 6
  • 48
  • 60
  • 1
    Worked beautifully - thanks. Just to clarify the table identifier: super.table(tableName, didSelectRowAtIndex: rowIndex) to target your table – Evernoob Jun 19 '15 at 10:49
  • @Evernoob - I removed the call to `super` altogether. Apple's sample code doesn't make a call to `super`. – hgwhittle Jun 19 '15 at 12:36
  • Great - just tested it and yes that works too and is a better solution. – Evernoob Jun 19 '15 at 15:00
1

Updated to swift 3.1:

There is no need to use WKInterfaceTable because now the function is located inside the UITableViewController.

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

    let ren : Int = indexPath.row

    print ("Row \(ren)")
}
Guillermo
  • 159
  • 1
  • 3