WatchKit中的表-WKInterfaceTable

一、创建一个WKInterfaceTable

1、我们可以通过Storyboard直接在当前WKInterfaceController中添加一个Table,Table默认有一个Table Row , 这个Table Row 相当于UITableView中的Cell,但是它是继承于NSObject。

WatchKit中的表-WKInterfaceTable_第1张图片
Paste_Image.png

2、我们可以在Table Row中定义样式,先在row中加入一个Lable

WatchKit中的表-WKInterfaceTable_第2张图片
Paste_Image.png

3、选中table连线到InterfaceController


WatchKit中的表-WKInterfaceTable_第3张图片
Paste_Image.png
Paste_Image.png

4、现在要创建一个Table Row类,继承于NSObject类,

WatchKit中的表-WKInterfaceTable_第4张图片
Paste_Image.png

并和storyboard中的TableRow绑定


WatchKit中的表-WKInterfaceTable_第5张图片
Paste_Image.png
WatchKit中的表-WKInterfaceTable_第6张图片
Paste_Image.png

然后给这个TableRow 起一个唯一的标识
identifier就是它的type

WatchKit中的表-WKInterfaceTable_第7张图片
Paste_Image.png

然后将lable连线到MyTableRow

WatchKit中的表-WKInterfaceTable_第8张图片
Paste_Image.png

WatchKit中的表-WKInterfaceTable_第9张图片
Paste_Image.png

这里会报错,因为lable是WKInterfaceLabel类的 ,所以我们要导入
WatchKit中的表-WKInterfaceTable_第10张图片
Paste_Image.png

5、在InterfaceController中加载列表,代码如下:

WatchKit中的表-WKInterfaceTable_第11张图片
Paste_Image.png

6、运行一下吧 :结果如下:

WatchKit中的表-WKInterfaceTable_第12张图片
Paste_Image.png

二、响应交互

我们需要点击某一行的回调,这里很像 UITableView 的 didSelectRowAtIndex, 我们直接在 InterfaceController 中添加 table:didSelectRowAtIndex 方法。
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex;

Paste_Image.png

你可能感兴趣的:(WatchKit中的表-WKInterfaceTable)