Search code examples
ioswatchkitapple-watch

How to set tag to a Button in Apple Watch


I am trying to image gallery in apple watch. I am putting a table with two buttons in a row. So for selection of image I need to set tag to a button. Can we do it in watch kit.


Solution

  • Whilst you can't set a tag on the buttons there are a couple of way you can achieve what you're after. From what I can establish from your comment you have a table with a custom row controller in it, and in each row you have 2 buttons?

    As you can't tag the buttons you could assign the method they call to individual methods defined in your custom row controller. That will give you which button was pressed. To find out the index of the row controller, you could expose a variable in the header of your row controller and set that with the value that you would have used as a tag when populating the table. The button methods will be calling the method in the instance of the row controller so the variable is in scope.

    The following link helped me build my table based app for WatchKit: https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/Tables.html