Getting User Input from a Text Field

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

  1. man2manno macrumors member

    Joined:
    Mar 21, 2009
    #1
    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

    Joined:
    Jun 10, 2008
    #2
    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

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

    hiddenpremise

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

    Joined:
    Jun 10, 2008
    #5
    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

    Joined:
    Mar 21, 2009
    #6
    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
     

Share This Page