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

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
Hey guys, I am new to all this and I am sorry for such a noobie question, but no matter where I go I just can't find it. So I am trying to make an iphone app and I want to get an integer value from the user through a text field, so i could then do some math with the number and display is back on the app.

I got the text field working fine but I need to know how to get the value of what is in the text field as an integer, not a string, so when a button is pressed it does some math. Which file is that done in the header or the implementation file?

here is my Header file (if needed):

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface MainView : UIView {
IBOutlet UITextField *textInput;
IBOutlet UILabel *textOut;
int x;
}
- (IBAction)pressMe;
 

kalimba

macrumors regular
Jun 10, 2008
102
0
Hey guys, I am new to all this and I am sorry for such a noobie question, but no matter where I go I just can't find it. So I am trying to make an iphone app and I want to get an integer value from the user through a text field, so i could then do some math with the number and display is back on the app.

I got the text field working fine but I need to know how to get the value of what is in the text field as an integer, not a string, so when a button is pressed it does some math. Which file is that done in the header or the implementation file?

here is my Header file (if needed):

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface MainView : UIView {
IBOutlet UITextField *textInput;
IBOutlet UILabel *textOut;
int x;
}
- (IBAction)pressMe;
Do you want someone to give you a fish, or would you be interested in learning how to fish? If the latter, try searching the Apple documentation for UITextField.
 

kalimba

macrumors regular
Jun 10, 2008
102
0
Code:
int myInt = [[textInput text] intValue];

You use the text property of the UITextField class to get a string. The next step would be to look at the documentation for NSString. Turns out there is an instanced method called intValue.

:)

Go catch some fish,
W
That's not catching fish, at least not in the true sense! That's just grabbing a fish from a net!! ;)
 

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
Thanks!

Haha Thanks so much for your help guys I was able to figure it out and got it all working thank a lot!!:D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.