WatchKit中的表-WKInterfaceTable
2015-09-02 本文已影响300人
X先生_vip
一、创建一个WKInterfaceTable
1、我们可以通过Storyboard直接在当前WKInterfaceController中添加一个Table,Table默认有一个Table Row , 这个Table Row 相当于UITableView中的Cell,但是它是继承于NSObject。

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

3、选中table连线到InterfaceController


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

并和storyboard中的TableRow绑定


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

然后将lable连线到MyTableRow


这里会报错,因为lable是WKInterfaceLabel类的 ,所以我们要导入<WatchKit/WatchKit.h>

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

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

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