如何在WKInterfaceTable中创建节 [英] How to create sections in WKInterfaceTable

查看:108
本文介绍了如何在WKInterfaceTable中创建节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can we create sections in table as there is no delegate for it. And is there any other way for creating sections or do we have to use two tables.

推荐答案

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

WKInterfaceTable is not so flexible like UITableView, but you can create rows manually, using different row types. And fill content for each cell according to its type.

参见文档:

Apple Watch编程指南:表格

WatchKit框架参考:WKInterfaceTable

例如,让我们创建包含两种行类型的表:

For example, let's create table with two row types:


  • headerRowType

  • detailRowType

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


完成!发挥想象力,创造更复杂的数据结构。

Done! Use your imagination and create more complex data structures.

这篇关于如何在WKInterfaceTable中创建节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆