WKInterfaceTable's didSelectRowAtIndex never gets called in WKInterfaceController

1.9k Views Asked by At

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?

3

There are 3 best solutions below

0
mm24 On BEST ANSWER

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.

0
Tal Brown On

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:

0
Edison On

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)
}