Andrew
Andrew

Reputation: 16051

How do I get the text from UITextField into an NSString?

I've tried various methods, which all give me warnings. Such as userName = [NSString stringWithFormat:@"%@", [yournamefield stringValue]]; which just gives me a warning of

'UITextField' may not respond to '-stringValue'

How do i do this?

Upvotes: 16

Views: 49505

Answers (4)

AshD
AshD

Reputation: 11

Two ways. It is a property and any property value can be accessed like this -

  • yournamefield.text
  • [yournamefield text]

Upvotes: 1

Jilouc
Jilouc

Reputation: 12714

Get the text inside the text field using the text property

NSString *name = yourNameField.text;

Upvotes: 39

Eric Chai
Eric Chai

Reputation: 650

Use the text property of UITextField:

NSString *userName = yourNameField.text;

Upvotes: 11

badgerr
badgerr

Reputation: 7982

How about:

userName = [NSString stringWithFormat:@"%@", yournamefield.text];

Upvotes: 1

Related Questions