如何在WKInterfaceTable中创build节

我们如何创build表格中的部分,因为没有委托。 还有什么其他的方式来创build部分或我们必须使用两个表。

WKInterfaceTable不像UITableView那么灵活,但可以使用不同的行types手动创build行。 并根据其types填写每个单元格的内容。

请参阅文档:

Apple Watch编程指南:表

WatchKit框架参考:WKInterfaceTable

例如,让我们创build两种行types的表:

  • headerRowType
  • detailRowType

    #define type1 @"HeaderRowType" #define type2 @"DetailRowType" // You also must create two classes: HeaderRowType and DetailRowType - controllers for these two types // preparing datasource: fill rowTypes and tableObjects NSArray* rowTypes = @[type1, type2, type2, type2, type1, type2, type2]; // types for table with 1 header cell and 3 detail cells in first "section", 1 header and 2 detail cells in second "section" // set types! self.someTable - WKInterfaceTable, associated with table in UI [self.someTable setRowTypes:rowTypes]; for (NSInteger i = 0; i < rowTypes.count; i++) { NSString* rowType = self.rowTypes[i]; if ([rowType isEqualToString:type1]) { // create HeaderRowType object and fill its properties. There you also can parse any data from main iPhone app. HeaderRowType* type1Row = [self.someTable rowControllerAtIndex:i]; // type1Row.property1 = ...; } else { DetailRowType* type2Row = [self.someTable rowControllerAtIndex:i]; // type2Row.property1 = ...; // type2Row.property2 = ...; } } 

完成! 使用你的想象力,创造更复杂的数据结构。

WatchKit表没有部分或标题,页脚,或编辑,search,数据源或委托。

表格部分不能从WatchKit API获得。 但是section只是一些带额外页眉/页脚视图的单元格,可以使用自定义devise的单元格来模拟:

WatchKit表与模拟部分

我创build了简单的WKInterfaceTable扩展 ,这有助于pipe理表。 下载示例应用程序