Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

just66horns

macrumors newbie
Original poster
May 6, 2009
21
0
Denver CO
Im having trouble with taking the typed numbers in a UItextfield, converting them to a float, and using them in a simple math method.
can anyone provide the code to take two UI textfeilds and, for example, add the values together...My math is a little more complex, but I have that part down.
Thanks in advance..
A link would be fine if easier...
 
Im having trouble with taking the typed numbers in a UItextbox, converting them to a float, and using them in a simple math method.
can anyone provide the code to take two UI text boxs and, for example, add the values together...My math is a little more complex, but I have that part down.
First, you'll want to make sure you using the right class names unless you want to confuse everybody. There is no UItextbox. I'm guessing you mean UITextField, although there is UITextView as well.

Second, you'll want to pull the text out of your UITextFields. There's a property for that. Then, with those NSStrings, you'll want to get their values as float. NSString has an instance method for that. Hope that helps.
 
using "UITextFeild" for numeric input

Yes, I meant UITextFeild, as you state. I went and fixed the original thread..

I will go and check that out. I think I know my problem. I'm new and confused.
(I was confusing VB's text box with ObjC...
I was using TextFeild in the code, but I only said text box here
 
but...

to get the text, I need
Code:
@property(nonatomic, copy) NSString *text;

Is this appropriate for a double, or do I then take the text, and declare it a double, therefore the property statement would be..

something like
Code:
@property(nonatomic, copy) NSnumber *textNumber;
 
to get the text, I need
Code:
@property(nonatomic, copy) NSString *text;
I'm sorry. I'm a little confused at what you're trying to do there. That's how the text property is defined, not how you use it. To you use that property (or assign via the accessor method; which the dot notation does behind the scenes anyways) either
Code:
NSString *textValue = aTextField.text;
or
Code:
NSString *textValue = [aTextField text];
 
Got it working

Thanks,
That got it!
doubleValue did not work, but floatValue did.
Excuse my thickness, and thanks for the help. My app is reaching functionality.. But there will be more questions.

Code:
	float m = [textFieldM.text floatValue];
	float g = [textFieldG.text floatValue];
	float fy = m / g;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.