首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >didSelectRowAtIndex没有被叫到WKInterfaceTable

didSelectRowAtIndex没有被叫到WKInterfaceTable
EN

Stack Overflow用户
提问于 2016-03-19 17:29:40
回答 3查看 801关注 0票数 4

我在故事板中创建了一个从WKInterfaceTableCell到另一个WKInterfaceController (称为DetailInterfaceController)的推子。

当我点击行时,不会调用didSelectRowAtIndex

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

TableInterfaceController

不调用didSelectRowAtIndexPath print语句。

代码语言:javascript
复制
@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

标签未设置

代码语言:javascript
复制
@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.
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-03-19 17:49:29

为什么没有被调用:

table:didSelectRowAtIndex:不被调用是正常的,因为您使用了一个情节提要。来自WKInterfaceController文档:

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

如何传递选定的行数据:

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

代码语言:javascript
复制
override func contextForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> AnyObject? {
    if segueIdentifier == "someSegueIdentifier" {
        return objectsArray[rowIndex]
    }
    return nil
}
票数 6
EN

Stack Overflow用户

发布于 2019-08-21 00:13:14

注意,table:didSelectRowAtIndex:不会因为另一个明显的原因而工作:WKInterfaceButton放在行上,用户点击它。在这种情况下,只为按钮触发tap事件。委托方法将无法工作。解决方案是将WKInterfaceButtonWKInterfaceTable行中删除。

票数 0
EN

Stack Overflow用户

发布于 2021-04-08 09:13:25

我也有同样的问题,结果是我在故事板中没有选中我的行项的“可选”框。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36104830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档