3

I have a WKInterfaceController and I added a table as following:

// .h

@interface InterfaceController : WKInterfaceController
@property (weak, nonatomic) IBOutlet WKInterfaceTable *table;
@end

// .m
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"did select");
}

- (void)table:(WKInterfaceTable *)table
didSelectRowAtIndex:(NSInteger)rowIndex{
    NSLog(@"did select new");
}

However neither of the two methods gets called. I was unable to find any protocol declaration for WKInterfaceTable and neither any delegate property on the table.

Is there something that I am missing here?

mm24
  • 9,280
  • 12
  • 75
  • 170

3 Answers3

7

I found out that the method was never called because I had set a segue to be triggered on selection of the row on Interface builder.

It seems that that by having no delegation and table protocols once you set a delegate it stops the didSelectRow method from being called.

mm24
  • 9,280
  • 12
  • 75
  • 170
3

In Apple's WKInterfaceController document it states that if you do not have any actions or segues then the method called is: - table:didSelectRowAtIndex:

If you use segues then the methods called are:

For buttons: - contextForSegueWithIdentifier:

For tables: - contextForSegueWithIdentifier:inTable:rowIndex:

Tal Brown
  • 126
  • 6
1

Swift 4

Here’s an example of selecting a WKInterfacetable row in a REST/JSON implementation.

Create a context property instance of the array class instead of using self.pushController.

override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
    let message = messageObjects[rowIndex]
    presentController(withName: "MessageView", context: message)
}
Edison
  • 11,881
  • 5
  • 42
  • 50