allocate
allocate

Reputation: 1343

Using text input value as a float

I'm trying to use the text value from a text field as a float (to update a slider), but it's apparently not as straight-forward as I thought.

self.speedSlider.value = self.numberOfSecs.text

That errors because an NSString is expected. I also can't cast the text into a float, it seems.

Any help is appreciated.

Upvotes: 1

Views: 907

Answers (2)

Dinesh
Dinesh

Reputation: 6532

Try this code below:

self.speedSlider.value = [self.numberOfSecs.text floatValue];

You must Convert String to Float...!

Upvotes: 0

Vladimir
Vladimir

Reputation: 170829

You can extract value using floatValue method (if your string represents a valid number):

self.speedSlider.value = [self.numberOfSecs.text floatValue];

Upvotes: 1

Related Questions