ios – 如何在WKInterfaceTable中创建节

前端之家收集整理的这篇文章主要介绍了ios – 如何在WKInterfaceTable中创建节前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们如何在表中创建部分,因为没有委托.是否有任何其他方式来创建部分或我们必须使用两个表.

解决方法

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

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

原文链接:https://www.f2er.com/iOS/328639.html

猜你在找的iOS相关文章