我有一个带有 WKInterfaceButton
的 WKInterfaceTable
TableView 。
如何从 TableView 向按钮添加目标操作。由于没有标签属性,我无法处理它。
最佳答案
如果您的 WKInterfaceButton
包含在行 Controller 中,则以下是一种确定点击了哪一行按钮的方法:
- 将您的
WKInterfaceButton
添加到行 Controller ,并使用界面构建器将按钮的操作连接到您的行 Controller 类 - 向行 Controller 添加一个属性,以允许您引用数据(例如,对数据或标签的弱引用)
- 向行 Controller 添加一个属性,允许您将界面 Controller 设置为委托(delegate)
- 为委托(delegate)创建一个协议(protocol),允许您传递数据引用
- 初始化每个行 Controller 时,请务必设置数据和委托(delegate)属性
在行 Controller 中处理按钮操作时,调用您在协议(protocol)中定义的委托(delegate)方法。像这样的东西:
- (void)rowController:(MyRowControllerClass *)rowController didSelectRowWithTag:(NSInteger)tag
在界面 Controller 中处理此委托(delegate)方法以完成任何必要的工作。
我在自己的 Watch 应用中使用了这种技术,效果非常好。
关于ios - WKInterfaceTable 中的 WKInterfaceButton 事件处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30391698/