How Do I Get the NSString from a UITextField

Discussion in 'iOS Programming' started by kaydell.leavitt, Apr 20, 2010.

  1. kaydell.leavitt macrumors regular

    Joined:
    Apr 19, 2010
    #1
    Hi,

    Will somebody help me to get an NSString from a UIText field?

    This is what I'm guessing at, but I don't know where to look to see how to do this right.

    Code:
    #import <UIKit/UIKit.h>
    
    @interface MarginCalcViewController : UIViewController {
    	IBOutlet UITextField *costDisplay;
    	IBOutlet UITextField *priceDisplay;
    	IBOutlet UITextField *marginPercentDisplay;
    }
    - (IBAction) calculateCost;
    - (IBAction) calculatePrice;
    - (IBAction) calculateMarginPercent;
    @end
    ... then, in the implementation, I have the following which doesn't work:

    NSString string = [costDisplay textValue]; <<< warning, may not respond to -textValue


    Thanks for taking the time to read my post.

    -- Kaydell
     
  2. zed2 macrumors 6502a

    Joined:
    Jul 17, 2004
    Location:
    Bucks
    #2


    NSString *string = costDisplay.text;

    Have you looked at the xcode help documentation, it has all the functions and parameters you can call on all the defined objects.
     
  3. kaydell.leavitt thread starter macrumors regular

    Joined:
    Apr 19, 2010
    #3
    Thanks

    Thanks for your help.

    This is what is working for me now.

    NSString *string = [costDisplay text];

    -- Kaydell
     
  4. MrCrispy macrumors member

    MrCrispy

    Joined:
    Apr 10, 2008
    Location:
    Jacksonville, Florida
    #4
    if you @synthesize your iboutlets in your implementation you can use the dot notations

    Code:
    @synthesize costDisplay;
    @synthesize priceDisplay;
    @synthesize marginPercentDisplay;
    
    and that would allow you to access them via

    Code:
    NSString *string = costDisplay.text;
    
     

Share This Page