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

By | December 18, 2017
Questions:

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?

Answers:

Get the text inside the text field using the text property

NSString *name = yourNameField.text;

Questions:
Answers:

Use the text property of UITextField:

NSString *userName = yourNameField.text;

Questions:
Answers:

How about:

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

Questions:
Answers:

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

  • yournamefield.text
  • [yournamefield text]

Leave a Reply

Your email address will not be published. Required fields are marked *