0

我正在使用iOS SDK 8.3并尝试按照本教程在手表套件应用程序中创建一个表。

我在 iWatch 应用程序的界面控制器上添加了一个表,然后将其链接到我的 InterfaceController。我创建了一个自定义行类并将该行链接到行控制器类。然后我在行中添加了几个项目并将它们链接到行控制器类中的插座。但是我得到一些错误:

在此处输入图像描述

这是我的接口控制器类:

#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>

@interface InterfaceController : WKInterfaceController

@property (strong, nonatomic) NSArray *devicesArray;

@property (weak, nonatomic) IBOutlet WKInterfaceGroup *devicesTable;

@end

这是触发错误的代码:

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];
    NSLog(@"%@ initWithContext", self);
    self.devicesArray = @[@"type A", @"type B"];
    [self.devicesTable setNumberOfRows:self.devicesArray.count withRowType:@"MyTableRowController"];

    [self.devicesTable enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

        MyTableRowController* row = [self.devicesTable rowControllerAtIndex:idx];

        [row.deviceType setText: (NSString*)obj];
        [row.logo setImage:[UIImage imageNamed:(NSString *)obj]];

    }];

在此处输入图像描述

4

2 回答 2

2

devicesTable被声明为WKInterfaceGroup支持你正在调用的方法。我确定您打算使用WKInterfaceTable. 您可能无意中从组中拖动了表的连接,而不是 Interface Builder 中的表。

于 2015-04-15T13:27:05.687 回答
1

看了教程,好像有点糊涂了。

WKInterfaceGroup用于"MyTableRowController"您创建的子类。

主要"InterfaceController"应该有 devicesTable 作为WKInterfaceTable

WKInterfaceTable上的 Apple Doc

WKInterfaceGroup上的 Apple Doc

于 2015-04-15T13:28:47.357 回答