表格行中的WKInterfaceSwitch或WKInterfaceButton-触摸了哪一行? [英] WKInterfaceSwitch or WKInterfaceButton in a table row -- which row was touched?

查看:133
本文介绍了表格行中的WKInterfaceSwitch或WKInterfaceButton-触摸了哪一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Apple Watch应用程序中有一个表,其中包含WKInterfaceSwitch的行.同一行控制器有10行,其中包括一个开关.换句话说,表的10个不同行中有10个开关,其中每一行都是同一行控制器的实例.

I have a table in my Apple Watch app with rows that include a WKInterfaceSwitch. There are 10 rows of the same row controller, which includes a switch. In other words, there are 10 switches in 10 different rows of a table where each row is an instance of the same row controller.

当用户触摸开关并更改其状态时,将调用action方法,但不传递对开关的引用,仅传递其新值.与WKInterfaceButton相似,与UIKit不同,没有引用被传递.

When a user touches a switch and changes its state, the action method is called, but a reference to the switch is not passed, only its new value. Similarly for WKInterfaceButton -- unlike UIKit, no reference is passed.

那么我怎么知道10个开关(或按钮)中的哪一个被触摸了?

So how do I know which of the 10 switches (or buttons) was touched?

理解我无法为每个开关的动作分配不同的选择器,因为它们都在同一类的实例(即行控制器)中.

Understand that I cannot assign a different selector for the action of each switch because they are all in instances of the same class, namely the row controller.

是否有可能只是不可能?

Is it possible that it is just not possible?

推荐答案

您可以通过向行控制器类添加自定义委托来实现.配置行控制器时,请将接口控制器设置为委托.然后,确保在行控制器中处理开关/按钮动作.呼叫代表并传递您可能在行控制器中配置的任何其他信息.

You can accomplish this by adding a custom delegate to your row controller class. When you configure the row controller, set your interface controller as the delegate. Then, make sure you handle your switch/button action in the row controller. Call the delegate and pass along whatever other information you may have configured in your row controller.

这篇关于表格行中的WKInterfaceSwitch或WKInterfaceButton-触摸了哪一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆