1

我想在 InterfaceController 中输入一个 if 语句,它基本上像 -

if label.text == "Hello" {
//execute some code
}

WKInterfaceLabel似乎只是拥有setText()财产。那么如何访问WKInterfaceLabel's text 属性?提前致谢!

4

1 回答 1

2

简短的回答:你不能。

更长的答案,将字符串存储在一个单独的变量中并将其用于if语句。

class InterfaceController: WKInterfaceController {

    @IBOutlet var myLabel: WKInterfaceLabel!
    var myString : String = ""

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

        myString = "hello"
        myLabel.setText(myString)

        if myString == "hello" {

            //so awesome stuff here

        }
        // Configure interface objects here.
    }

    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
    }

    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        super.didDeactivate()
    }

}
于 2015-09-05T16:12:47.920 回答