How can I capture a table row press action in Swift WatchKit?

783 views Asked by At

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!

2

There are 2 answers

3
hgwhittle On BEST ANSWER

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
}
0
Guillermo On

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)")
}