Yetik Yetik - 6 months ago 19
iOS Question

How to get a Text Field's text in XCode

I made a Text Field with interface builder. How can I get its text to use somewhere else?

Is there something like:

string text = myTextField.Text;

If so, how can I name my text field?


So the first thing you want to do is create a property in the .h file of the view controller files associated with your xib file like so:

    @property (strong, nonatomic) IBOutlet UILabel *aLabel;

Next in the .m file you need to synthesize it like so:

    @synthesize aLabel;

Within you implementation tag.

Now in interface builder control click where it says "File's Owner" on the left side of the screen in Xcode 4.3 hold down and drag over the label and let go. Then in the popup select the name of the property you created. Now in the viewDidLoad method of your view controller you can get at your value like so: