ios - WatchKit 表是空白的

标签 ios objective-c tableview watchkit

我正在尝试在 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/

相关文章:

iOS - 将视频合并到一帧与自己的帧

ios 使用 mfMailComposer 发送 docx 附件失败

c# - Xamarin iOS - 如何发送电子邮件

iphone - 创建类似于所选 UITableViewCell 的 UILabel 背景

ios - 在不使用XML的情况下更新sqlite数据库

ios - 删除索引路径错误处的行

ios - 如何在 swift 中从另一个 View Controller 重新加载 tableview

JavaFX TableView 不显示内容

ios - Xcode代码文档

iphone - 如何播放m3u8音频文件?