简体   繁体   English

如何在 Swift WatchKit 中捕获表格行按下动作?

[英]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.当我运行 proobject 时,行会显示在屏幕上,甚至还有一个按下动画,但 xcode 不会让我将表行作为 IBAction 连接到其控制器。 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.在这种情况下,我不能使用 segue,它需要像按下按钮一样,但最好是在整个表 rown 上,我宁愿不将按钮插入其中。 Any help appreciated, thanks!任何帮助表示赞赏,谢谢!

You want to override the table:didSelectRowAtIndex function.您想覆盖table:didSelectRowAtIndex函数。 It is a method on WKInterfaceController .它是WKInterfaceController上的一个方法。

override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    // Handle row selection
}

Updated to swift 3.1:更新到 swift 3.1:

There is no need to use WKInterfaceTable because now the function is located inside the UITableViewController.无需使用 WKInterfaceTable,因为现在该函数位于 UITableViewController 内部。

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

    let ren : Int = indexPath.row

    print ("Row \(ren)")
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM