didSelectRowAtIndex not being called for WKInterfaceTable

Viewed 800

I have created a push segue in the storyboard from an WKInterfaceTableCell to another WKInterfaceController (called DetailInterfaceController).

When I tap on the row, didSelectRowAtIndex is not being called.

Does anybody know where I am going wrong, and how I can pass the string?

TableInterfaceController

didSelectRowAtIndexPath print statement is not called

@IBOutlet var table: WKInterfaceTable!
var objectsArray = ["1","2","3"]
var object: String!

override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    self.object = self.objectsArray[rowIndex]

    print(" object title: \(self.object)")
}


override func contextForSegueWithIdentifier(segueIdentifier: String) -> AnyObject? {
    // You may want to set the context's identifier in Interface Builder and check it here to make sure you're returning data at the proper times

    // Return data to be accessed in ResultsController
    return self.object
}

DetailsInterfaceController

The label is not set

@IBOutlet var label: WKInterfaceLabel!

override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)

    // Make sure data was passed properly and update the label accordingly
    if let val: String = context as? String {
        self.label.setText(val)
    } else {
        self.label.setText("")
    }
    // Configure interface objects here.
}
3 Answers

Notice that table:didSelectRowAtIndex: won't be worked by another one obvious reason: WKInterfaceButton is placed on the row and the user taps on it. In this case, the tap event will only be fired only for button. The delegate method won't work. The solution is removing WKInterfaceButton from the row of WKInterfaceTable

I had the same problem, and it turns out that I had unchecked the "selectable" box of my row item in the storyboard

overview

Related