0

I want to get a float value from a WKInterfaceLabel. As there is no getter method for WKInterfaceLabel, using float x = ([_someText.text floatValue]); will just give me no getter method error. Any ideas?

I tried here Compare WKInterfaceLabel Text to Another NSString to find a solution, using self.label.accessibilityValue simply returns nil when acessing the accessibilityValue

Community
  • 1
  • 1
JSA986
  • 5,870
  • 9
  • 45
  • 91
  • Did you first *set* the accessibilityValue ? To use the solution in that thread you linked to, you must "mirror" the label text with the accessibilityValue-- always set them both to the new value, is the only way it will work. – zeppenwolf Apr 19 '15 at 16:37
  • Yep, it was `set` in the first instance and read from that. Always getting nil – JSA986 Apr 19 '15 at 16:39

1 Answers1

0

A few different solutions / ideas:

I would make your WKInterfaceLabel a property and synthesize it, then you are able to retrieve float values from your label just like you would with a regular UILabel. I've successfully done this with no issues. I checked out the post that you linked and they said there is currently no way to retrieve the text values... I don't know if something was updated or not because I can retrieve float values, text values etc in WatchKit just fine. For retrieving or settingy code looks exactly like this:

(Declared privately in the .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;
    }
 }

Now if you're trying to just receive a random float value rather than create, you had to of retrieved or set that float value SOMEWHERE in your code or if retrieved from a server, somewhere in the data. Save that, and use it.

Henry F
  • 4,960
  • 11
  • 55
  • 98
  • My `WKInterfaceLabels` are properties already. How are you obtaining a getter? `WKInterfaceLabel` is a read from property only with no getter method? (Xcode V6.3) I cant get anything from WKInterface label at all? – JSA986 Apr 19 '15 at 21:31
  • Did you ever find a solution? I have run into the same brick wall? – d.altman Apr 29 '15 at 05:44
  • @d.altman I wish the has site private messaging so that I could message everybody my project showing them how I did it. I will check it out and keep you all updated via this posting – Henry F Apr 29 '15 at 15:01