-1

Possible Duplicate:
retrieving integer value from the UITextField into a NSInteger variable

I have users fill in a text box with a number. I want to use this number in a calculation; how can i put it in a variable? So far I only have:

NSInteger *answer = results........
Community
  • 1
  • 1
Tim
  • 1,056
  • 4
  • 17
  • 34

2 Answers2

3

Use intValue or integerValue from the NSString class.

int answer = [myTextField.text intValue];

or

NSInteger answer = [myTextField.text integerValue];

You can also use floatValue and doubleValue for floating-point inputs.

Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
1
NSInteger answer = [textField.text integerValue];

OR

int answer = [textField.text intValue];
daihovey
  • 3,485
  • 13
  • 66
  • 110