Sunday, August 10, 2014

How to retrieve a Text Field value in iOS/iPad/iPhone programming in Xcode

1) Drag the Text Field onto your storyboard

2) On the top right side of the screen, you'll see a button that looks like a tux with a bow tie.  It is labeled "Show the Assistant Editor".  Click on that button

3) You should see the storyboard side-by-side to a text window showing code.  Make sure that the .h is showing, such as ViewController.h - you can switch the file by clicking on "Automatic".

4) Scroll the text edit window down to the end, right before "@end".

5) Hold down control, and drag the Text Field to the ViewController.h text edit windows, and drop it right before the "@end".  Type in any name for the Text Field, such as textEntryField.

6) In the callback function (not necessarily a callback function for the Text Field) in the ViewController.m file, you can retrieve the value of the Text Field through "_textEntryField.text".  For example:


NSString* entryText = _textEntryField.text;
NSLog(@"The text in the Text Field is: %@", entryText);

No comments: