views:

85

answers:

3

How can i get the value of a UITextField? Some sample code to attach it to an NSString would be fab!

P.S - Happy New Year!

+2  A: 
NSString *tf_text = [ yourTextField text ];
Jacob Relkin
In UIKit/Mobile Darwin, you can use properties as well: tf_text = yourTextField.text;
rpj
A: 

If in doubt always look at the documentation it'll give you the answer faster than asking on here!

In this case: UITextField and for future reference: iPhone class documentation

James Raybould
A: 

The UITextField has to be connected to your file through Interface Builder, and declared as an IBOutlet in your header file:

IBOutlet UITextField *textField;

Then you'd access it in your methods as:

NSString *enteredText = [textField text]; // Or textField.text
Jason B
No it doesn't, you can build an entire interface from within code.
Jacob Relkin
You're right; I didn't consider that the OP may be doing so. My mistake. It should be connected through as an IBOutlet if you are using Interface Builder to build the UI.
Jason B