一、创建一个WKInterfaceTable
1、我们可以通过Storyboard直接在当前WKInterfaceController中添加一个Table,Table默认有一个Table Row , 这个Table Row 相当于UITableView中的Cell,但是它是继承于NSObject。
Paste_Image.png2、我们可以在Table Row中定义样式,先在row中加入一个Lable
Paste_Image.png3、选中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。
然后将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;
网友评论