2

我只需要检查选择了哪一行在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;
    }
}
4

2 回答 2

4

确保...

  1. WKInterfaceTable通过 IBOutlet 连接到您的 Storyboard 元素。
  2. 行控制器的 rowType 标识符在 Storyboard 中设置:在此处输入图像描述
  3. 行控制器的类标识符在 Storyboard 中设置: 在此处输入图像描述
  4. 您已经覆盖了正确的WKInterfaceController方法:

    override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    
    }
    
于 2015-06-19T13:05:56.923 回答
0

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

  override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
        let string = data[rowIndex]
        self.delegate?.didSeletStyle(style, string: string, index: rowIndex)
        popController()
    }

  private func reloadTable() {
        for i in 0 ..< table.numberOfRows {
            let row = table.rowControllerAtIndex(i) as! tableRow
            row.label.setText(data[i])
        }
    }

private func getData(style: Style) {
    if style == .Friend {
        data = ["a","b","c","d"]
    }

    table.setNumberOfRows(data.count, withRowType: "tableRow")
    reloadTable()
}
于 2015-06-19T12:50:22.280 回答