WKInterfaceButton event handling in WKInterfaceTable

拥有回忆 提交于 2019-12-03 21:40:53

If your WKInterfaceButton is contained within a row controller, here is one method to determine which row's button was tapped:

  • Add your WKInterfaceButton to the row controller and use interface builder to connect the button's action to your row controller class
  • Add a property to your row controller that allows you to reference your data (for example, a weak reference to your data or a tag)
  • Add a property to your row controller that allows you to set your interface controller as a delegate
  • Create a protocol for the delegate that allows you to pass the data reference
  • When initializing each row controller, be sure to set the data and delegate properties
  • When the button action is handled in the row controller, call the delegate method that you defined in your protocol. Something like:

    - (void)rowController:(MyRowControllerClass *)rowController didSelectRowWithTag:(NSInteger)tag

  • Handle this delegate method in your interface controller to do whatever work is necessary.

I use this technique in my own Watch app, and it works very well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!