4

WKInterfaceTableCell我在情节提要中创建了一个从一个到另一个WKInterfaceController(称为DetailInterfaceController)的推送序列 。

当我点击该行时, didSelectRowAtIndex没有被调用。

有谁知道我哪里出错了,以及如何传递字符串?

表接口控制器

didSelectRowAtIndexPath print不调用语句

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

详细信息接口控制器

未设置标签

@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.
}
4

3 回答 3

6

为什么不叫:

table:didSelectRowAtIndex:由于您使用了故事板转场,因此不被调用是正常的。从WKInterfaceController文档中:

如果您将操作方法​​连接到情节提要文件中的表,WatchKit 不会调用此方法

如何传递选定的行数据:

您应该使用contextForSegueWithIdentifier:inTable:rowIndex:返回所选行的上下文:

override func contextForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> AnyObject? {
    if segueIdentifier == "someSegueIdentifier" {
        return objectsArray[rowIndex]
    }
    return nil
}
于 2016-03-19T17:49:29.177 回答
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

于 2019-08-21T00:13:14.173 回答
0

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

overview

于 2021-04-08T09:13:25.197 回答