Getting User Input from a Text Field

Discussion in 'iOS Programming' started by man2manno, Mar 21, 2009.

  1. man2manno macrumors member

    Mar 21, 2009
    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;
  2. kalimba macrumors regular

    Jun 10, 2008
    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.
  3. CocoaPuffs macrumors 68010

    Aug 23, 2008
    He wants a boat load of fish.
  4. hiddenpremise macrumors regular


    Jul 25, 2008
    Somewhere between my imagination and reality
    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,
  5. kalimba macrumors regular

    Jun 10, 2008
    That's not catching fish, at least not in the true sense! That's just grabbing a fish from a net!! ;)
  6. man2manno thread starter macrumors member

    Mar 21, 2009

    Haha Thanks so much for your help guys I was able to figure it out and got it all working thank a lot!!:D

Share This Page