Yetik Yetik - 1 year ago 152
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?

Answer Source

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:

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