在 WKInterfaceTable 的 select 行将数据传输到 Iphone

On select row of WKInterfaceTable transfer data to Iphone

我正在为 iOS 应用程序制作手表应用程序。我从手表主 InterfaceController 中的父应用程序获取数据并将其传递给其他 InterfaceController 以创建 table。这里配置代码 table:

- (void)configureTableWithData:(NSArray*)dataObjects {

    [self.table setNumberOfRows:[dataObjects count] withRowType:@"rowType"];
    for (NSInteger i = 0; i < self.table.numberOfRows; i++) {

        RowType* row = [self.table rowControllerAtIndex:i];
        NSObject* object = [dataObjects objectAtIndex:i];

        [row.titleName setText:[object valueForKey:@"CharCode"]];
        [row.bottomValue setText:[object valueForKey:@"Value"]];
    }
}

当我 select 行时,我想将数据传输回第一页。需要更改首页上的一些标签。我正在通过将数据传输到父应用程序并将其 return 返回到主 InterfaceController

- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {

     //Here must be dictionary, where I put row

     [WKInterfaceController openParentApplication:data reply:^(NSDictionary *replyInfo, NSError *error) {
          NSLog(@"data transfer");
     }];

     [self dismissController];
}

如何获取行的数据? (row.titleName, row.value) 可能是个愚蠢的问题,我还是个初学者,但我能搞定。我尝试在控制台 row.titleName 和 row.bottomValue 上打印,当然我一无所获。 (对不起我的英语,不是我的母语)我错过了什么?

我在 tableview 中的 watch kit 也有同样的问题。现在我们只设置单元格标签中的文本不返回所以你必须这样做

- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {

     //Here must be dictionary, where I put row
     NSDictionary* object = [dataObjects objectAtIndex:rowIndex];
     NSLog("used object as you want");

     [WKInterfaceController openParentApplication:object reply:^(NSDictionary *replyInfo, NSError *error) {
          NSLog(@"data transfer");
     }];

     [self dismissController];
}