Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 512
Evernoob Avatar asked Jun 18 '15 23:06

Evernoob


2 Answers

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
}
like image 140
hgwhittle Avatar answered Nov 01 '22 18:11

hgwhittle


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)")
}
like image 1
Guillermo Avatar answered Nov 01 '22 18:11

Guillermo