Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 938
Yetik Avatar asked Jun 18 '12 15:06

Yetik


1 Answers

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:

   self.alabel.text
like image 134
Greg Price Avatar answered Oct 12 '22 22:10

Greg Price