1
一個WKInterfaceLabel的Text屬性我想鍵入InterfaceController if語句基本上去喜歡 -如何訪問Apple關注應用
if label.text == "Hello" {
//execute some code
}
但WKInterfaceLabel
似乎只是有setText()
財產。那麼如何訪問WKInterfaceLabel
的文本屬性?提前致謝!
一個WKInterfaceLabel的Text屬性我想鍵入InterfaceController if語句基本上去喜歡 -如何訪問Apple關注應用
if label.text == "Hello" {
//execute some code
}
但WKInterfaceLabel
似乎只是有setText()
財產。那麼如何訪問WKInterfaceLabel
的文本屬性?提前致謝!
簡答:你不能。
較長的答案,將字符串存儲在一個單獨的變量中,並將其用於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()
}
}
再次感謝! –
回答每個問題的第一步:谷歌你遇到問題的類。這將永遠給你一個鏈接從蘋果與所有可用的功能,變量和類常量。 [WKInterfaceLabel類參考](https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceLabel_class/) –