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/) –