Tom Andrews Tom Andrews - 1 year ago 74
Objective-C Question

Setting variables from textbox values in objective-c

Sort of new to objective-c, just wondering how I can set a variable as a value from a textbox. I'm setting up my login screen and will be using a JSON request to process the variables.

@interface LoginController : UIViewController
IBOutlet UITextField *txtUsername;
IBOutlet UITextField *txtPassword;
IBOutlet UIButton *btnLogin;



Everything is defined in the above .h

@implementation LoginController

username = [txtUsername];

Just need to know the syntax to set that username variable to the text in the textbox when btnLogin is clicked. (.m file above)

Answer Source

You get the value of the text in the text field like so :

    NSString * username = [txtUsername text];

also please to the documentation of the UITextField

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download