作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我们如何在表中创建部分,因为它没有委托(delegate)。还有其他方法可以创建部分,还是我们必须使用两个表。
最佳答案
WKInterfaceTable 不像 UITableView 那样灵活,但您可以使用不同的行类型手动创建行。并根据其类型为每个单元格填充内容。
查看文档:
Apple Watch Programming Guide: Tables
WatchKit Framework Reference: WKInterfaceTable
例如,让我们创建一个具有两种行类型的表:
详细行类型
#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 = ...;
}
}
完成!发挥您的想象力,创建更复杂的数据结构。
关于ios - 如何在 WKInterfaceTable 中创建部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28803813/
我是一名优秀的程序员,十分优秀!