2015-03-02 55 views

回答

4

WatchKit表格没有章节或标题,页脚,或编辑或搜索,或数据源或代表。

+0

长呼吸.. AAAhhh sighhh – 2017-05-16 13:03:56

16

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

查看文档:

Apple Watch Programming Guide: Tables

WatchKit Framework Reference: WKInterfaceTable

例如,让我们创建表有两个行类型:

  • 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 = ...; 
        } 
    } 
    

完成!发挥你的想象力并创建更复杂的数据结构。

+0

如果你只是想要一个头,只要将一个带有标签的组拖放到它上面,并将它放在WKInterfaceTable上方,它就可以正常工作。 – GeneCode 2016-08-24 10:15:32

0

TableKit在WatchKit API中不可用。但部分仅仅是一组额外的页眉/页脚意见细胞,可以通过使用定制设计的细胞来模拟:

WatchKit table with simulated sections

我创建简单WKInterfaceTable extensions,来帮助管理表。下载Sample app