【问题标题】:How to add a button action in apple watch?如何在 Apple Watch 中添加按钮操作?
【发布时间】:2018-12-13 08:17:58
【问题描述】:

我正在尝试添加一个带有按钮的操作来更改标签中的文本,我为我的表格行创建了一个类,这是代码,当我尝试运行时,我什么也没看到。

import WatchKit
import Foundation

class MyRowController: NSObject {

    @IBOutlet weak var label: WKInterfaceLabel!
    @IBOutlet weak var button: WKInterfaceButton!

    @IBAction func buttonpress() {
        label.setText("ciao")
    }

}

【问题讨论】:

    标签: swift button action watchkit watch


    【解决方案1】:

    通常 watchOS 应用程序用户期望整行是按钮本身,这样您就可以通过委托回调 table(_:didSelectRowAt:) (https://developer.apple.com/documentation/watchkit/wkinterfacecontroller/1619575-table) 来响应对行的点击。如果您的内容没有被重复并且WKInterfaceGroup 就足够了,您可以将您的WKInterfaceButton 放入组中,然后其关联的@IBAction 将起作用。

    【讨论】:

      猜你喜欢
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多