iOSIOS开发iOS学习笔记

WatchKit中的表-WKInterfaceTable

2015-09-02  本文已影响300人  X先生_vip

一、创建一个WKInterfaceTable

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

Paste_Image.png

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

Paste_Image.png

3、选中table连线到InterfaceController


Paste_Image.png Paste_Image.png

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

Paste_Image.png

并和storyboard中的TableRow绑定


Paste_Image.png Paste_Image.png

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

Paste_Image.png

然后将lable连线到MyTableRow

Paste_Image.png Paste_Image.png
这里会报错,因为lable是WKInterfaceLabel类的 ,所以我们要导入<WatchKit/WatchKit.h>
Paste_Image.png
5、在InterfaceController中加载列表,代码如下: Paste_Image.png

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

Paste_Image.png

二、响应交互

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

Paste_Image.png
上一篇 下一篇

猜你喜欢

热点阅读