
The table row class must inherit from NSObject and you will want to add import WatchKit since this class will contain WatchKit objects: Name the file LightbulbAccessoryRow and ensure it is in the watchkittables WatchKit Extensions folder, group, and target. In the project navigator click on watchkittables WatchKit Extension and then go to File – New – File and choose an iOS Swift file. We now need to create a Swift class for our table row. Set the horizontal position of the button to Center. Set the image size to 32×32 and for the button set the size attributes to Size to Fit Content. In Interface.storyboard click on the group inside the LightbulbAccessoryRow and drag-and-drop an image and button inside the group. Now let’s define the content of the LightbulbAccessoryRow. Select the second Table Row Controller and for Identifier type ThermostatAccessoryRow. Each table row controller is responsible for managing their type of row.Ĭlick on the first Table Row Controller and in the Attributes inspector for Identifier type LightbulbAccessoryRow. Notice that there are now two Table Row Controllers. Now, we’ve established that we want two types of rows and we currently only have one, so click on the Attributes inspector for the table (not the row controller) and set the Rows value to 2: The table row controller implementation is in the extension (in this first iteration of WatchKit it should pointed out that implementation is always in the extension) and is a separate Swift class. If you have one more than one type of row you will have more than one row controller. The Table in WatchKit is the UI component which will manage the rows, and the row controller will manage the display of a type of row. In the screenshot above note that the Interface Controller contains a Table, and that Table contains a Table Row Controller. We’re going to stop and make the distinction now between a table and a row in WatchKit. After this step your watch interface should look like this: Note that the description for a WKInterfaceTable says “Displays one or more rows of data”. The other row type will contain a label and two buttons to increase and decrease the setpoint temperature on a thermostat.īring up your Watch App Interface.storyboard and drag and drop a Table onto the watch canvas. One row type will contain a lightbulb image and a button to toggle it on and off. We’re going to create a table with two types of rows. Home automation control is all about controlling accessories, and what better way to quickly view all of your accessories than with a table? WatchKit provides a table UI element with WKInterfaceTable. Open the watchkittables.xcodeproj project in Xcode 6.2 or higher (this is the first version with iOS 8.2 and WatchKit). Our starter app already has an Apple Watch target provided and supplementary images.
#Appcode watchkit table download#
Let’s get started! Head on over to Bitbucket and download the starter app. Bring up your Apple Watch, open your home automation app, and press Unlock. The Apple Watch interface will lend itself well to controlling home automation devices as it will eliminate things like digging your phone out of your pocket to unlock the door.

If you’ve been following or reading this blog for any period of time you will know that we’re passionate about home automation controls, and look forward to HomeKit in the market.
#Appcode watchkit table how to#
Today we’re going to show you how to use a WKInterfaceTable in your Apple Watch applications.
