WKInterfaceTable检测选择哪一行

时间:2015-06-19 11:32:04

标签: ios iphone watchkit wkinterfacetable

我只需要检查选择了哪一行来在WKInterfaceController之间传递数据。这是我的代码,但NSLog没有显示任何内容:

- (void)loadTableData {

     NSArray* items = [NSArray arrayWithObjects:@"cell 1 ",@"cell2 ", @"cell 3",@"cell4",nil];

    // Configure the table object (self.todoItems) and get the row controllers.
    [self.myTable setNumberOfRows:items.count withRowType:@"DinoNameRow"];
    NSInteger rowCount = self.myTable.numberOfRows;

    // Iterate over the rows and set the label for each one.
    for (NSInteger i = 0; i < rowCount; i++) {
        // Get the to-do item data.
        NSString* itemText = items[i];

        // Assign the text to the row's label.
        DinoNameRow* row = [self.myTable rowControllerAtIndex:i];
        [row.dinoName setText:itemText];
    }
}
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {

    switch (rowIndex) {
        case 0:
            NSLog(@"ROW 1");
            break;

        default:
            break;
    }
}

2 个答案:

答案 0 :(得分:3)

确保......

  1. 您的WKInterfaceTable已通过IBOutlet连接到您的Storyboard元素。
  2. 行控制器的rowType标识符在Storyboard中设置:enter image description here
  3. 行控制器的类标识符在Storyboard中设置: enter image description here
  4. 您已覆盖了正确的WKInterfaceController方法:

    override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    
    }
    

答案 1 :(得分:0)

我在项目中使用的以下代码运行良好。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>