由于没有委托,我们如何在表中创建部分。有没有其他方法来创建部分,或者我们是否必须使用两个表。
WKInterfaceTable 不像 UITableView 那样灵活,但您可以使用不同的行类型手动创建行。并根据每个单元格的类型填充内容。
看一下文档:
Apple Watch 编程指南:表格 https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/Tables.html#//apple_ref/doc/uid/TP40014969-CH14-SW1
WatchKit 框架参考:WKInterfaceTable https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceTable_class/index.html#//apple_ref/doc/uid/TP40014965
例如,让我们创建一个具有两种行类型的表:
- 标题行类型
-
详细信息行类型
#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 = ...;
}
}
完毕!发挥你的想象力,创建更复杂的数据结构。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)