当没有WKInterfaceLabel的getter方法时获取浮点值

时间:2015-04-19 16:08:07

标签: ios objective-c watchkit apple-watch

我想从WKInterfaceLabel获取浮点值。由于WKInterfaceLabel没有getter方法,因此使用float x = ([_someText.text floatValue]);只会给我一个getter方法错误。有什么想法吗?

我在此尝试Compare WKInterfaceLabel Text to Another NSString找到解决方案,在self.label.accessibilityValue

进行访问时,nil只返回accessibilityValue

1 个答案:

答案 0 :(得分:0)

一些不同的解决方案/想法:

我会让你的WKInterfaceLabel属性并合成它,然后你就可以从标签中检索浮点值,就像使用常规UILabel一样。我没有遇到任何问题我成功完成了这项工作。我检查了你链接的帖子,他们说目前无法检索文本值...我不知道是否有更新的东西,因为我可以在WatchKit中检索浮点值,文本值等。对于检索或设置代码看起来完全如下:

(在.m中私下声明)

@property (weak, nonatomic) IBOutlet WKInterfaceLabel *tempoLabel;
//
    - (void)setTempoFromInteger {
        self.tempoLabel.text = @"";
    if (tempo > 0 && tempo < 999) {
        NSString *tempoString = [NSString stringWithFormat:@"%i", tempo];
        self.tempoLabel.text = tempoString;
    }
 }

现在,如果您尝试仅接收随机浮点值而不是创建,则必须在代码中检索或设置浮动值SOMEWHERE,或者从服务器检索数据中的某个位置。保存,并使用它。