我正在尝试在 WatchKit 上创建一个表。由于某种原因,该应用程序在 WatchKit 中启动时只是空白。我已经确认这是一个表格问题(我添加了一个静态标签并且能够看到它)。我相信我也已正确连接所有 IBOutlets。我做错了什么?
我的 InterfaceController.h 中有以下代码:
@interface InterfaceController : WKInterfaceController {
NSMutableArray *listArray;
}
@property (weak, nonatomic) IBOutlet WKInterfaceTable *playlistTable;
接口(interface) Controller .m:
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Configure interface objects here.
listArray = [[NSMutableArray alloc] initWithObjects:@"Hello", @"Watch", @"World", nil];
[self setupTable];
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
- (void)setupTable {
[self.playlistTable setRowTypes:listArray];
for (int i = 0; i < self.playlistTable.numberOfRows; i++)
{
universalRow *row = [self.playlistTable rowControllerAtIndex:i];
[row.mainTitle setText:[listArray objectAtIndex:i]];
[row.subtitleLabel setText:@"subtitle!"];
}
}
和 NSObject 行类“universalRow”:
@interface universalRow : NSObject {
}
@property (nonatomic, weak) IBOutlet WKInterfaceLabel *mainTitle;
@property (nonatomic, weak) IBOutlet WKInterfaceLabel *subtitleLabel;
@end
最佳答案
setRowTypes:
接受一个字符串数组,这些字符串是您在 Storyboard中分配给行 Controller 的每个名称,而不是您要放入行中的数据。
您可能需要 [self.playlistTable setNumberOfRows:listArray.count withRowType:@"RowType"]
其中 @"RowType"
是您为行 Controller 指定的任何名称在 Storyboard中。
关于ios - WatchKit 表是空白的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30686912/