如何在 Swift WatchKit 中捕获 table 行按下操作?

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

我目前有一个包含一些动态行的 table。当我 运行 probject 行显示在屏幕上,甚至有一个按下动画但是 xcode 不允许我将 table 行作为 IBAction 连接到它的控制器。在这种情况下我不能使用 segue,它需要像按下按钮一样,但最好在整个 table rown 我不想在其中插入按钮。感谢任何帮助,谢谢!

您想覆盖 table:didSelectRowAtIndex 函数。这是 WKInterfaceController.

上的一个方法
override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    // Handle row selection
}

已更新至 swift 3.1:

不需要使用 WKInterfaceTable,因为现在该函数位于 UITableViewController 内部。

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

    let ren : Int = indexPath.row

    print ("Row \(ren)")
}