2

I just need to check which row was selected to pass data between WKInterfaceController. Here is my code, but NSLog doesn't show anything:

- (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;
    }
}
hgwhittle
  • 9,316
  • 6
  • 48
  • 60
iOS.Lover
  • 5,923
  • 21
  • 90
  • 162

2 Answers2

4

Make sure that...

  1. Your WKInterfaceTable is connected via IBOutlet to your Storyboard element.
  2. Your rowType identifier for the row controller is set in Storyboard:enter image description here
  3. Your Class identifier for the row controller is set in Storyboard: enter image description here
  4. You have overridden the correct WKInterfaceController method:

    override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    
    }
    
hgwhittle
  • 9,316
  • 6
  • 48
  • 60
  • In the step 3 , the Modulation is blank for me ! how should I fill it ? even my main IntefaceContoller is blank ! ! ! other parts are all OK ! – iOS.Lover Jun 19 '15 at 13:17
  • Those should be set with the Watch Extension's module name. In your file navigator pane on the left, you're looking for the folder that contains all your Watch classes. Should be something like `Watch Extension`. Set that in the module field with underscores for spaces. – hgwhittle Jun 19 '15 at 13:21
  • AHA !!! I found the solution that's because of I add `PUSH SEGUE to `another view Controller ! that was the problem – iOS.Lover Jun 19 '15 at 13:27
0

The code as below that I use in my project works well.

  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()
}
Alex Cheng
  • 829
  • 8
  • 20