4

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.
}
RileyDev
  • 2,950
  • 3
  • 26
  • 61

3 Answers3

6

Why it's not called:

It's normal for table:didSelectRowAtIndex: to not be called since you used a storyboard segue. From the WKInterfaceController documentation:

If you connected an action method to the table in your storyboard file, WatchKit does not call this method.

How to pass the selected row data:

You should use contextForSegueWithIdentifier:inTable:rowIndex: to return the context for the selected row:

override func contextForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> AnyObject? {
    if segueIdentifier == "someSegueIdentifier" {
        return objectsArray[rowIndex]
    }
    return nil
}
1

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

overview

Steve
  • 914
  • 8
  • 17
0

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

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194