9

我们如何在表中创建部分,因为它没有委托。还有其他方法可以创建部分还是我们必须使用两个表。

4

3 回答 3

17

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

看一下文档:

Apple Watch 编程指南:表格

WatchKit 框架参考:WKInterfaceTable

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

  • headerRowType
  • 详细行类型

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

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

于 2015-03-11T22:29:30.523 回答
5

WatchKit 表没有节、页眉、页脚、编辑、搜索、数据源或委托。

于 2015-03-02T11:14:11.950 回答
0

WatchKit API 不提供表格部分。但是部分只是一组带有额外页眉/页脚视图的单元格,可以使用自定义设计的单元格来模拟:

带有模拟部分的 WatchKit 表

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

于 2015-04-29T12:22:27.303 回答