Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCarter Randall
3,311 PointsAccessing and manipulating Integer values from a textField
I playing around with fun concepts and was wondering how you handle numeric inputs into a text field. I set the keyboard type to "number pad" and created IBOutlets from each value. How would one go about getting the input and inserting it into a formula? Here's a couple screen shots as an example:
https://www.dropbox.com/s/36fvft0olpyf5tq/Screenshot%202015-01-09%2015.37.38.png?dl=0 https://www.dropbox.com/s/7b99v774ed8mbc0/Screenshot%202015-01-09%2015.39.03.png?dl=0
1 Answer
Stephen Whitfield
16,771 PointsIf you want to get the value of a text field, you simply access its "text" property
var textFromTextField = self.textField.text
EDIT: Just now realizing you're working in Objective-C
UITextField *textField = [[UITextField alloc] initWithFrame:self.someObj.frame];
textField.text = @"Here I am";
NSString *textFromTextField = textField.text;
Stephen Whitfield
16,771 PointsStephen Whitfield
16,771 PointsYou're just converting a text value to an integer and encapsulating that with an NSNumber in that line of code. It shouldn't be any more different getting a numeric value from a text field as it is getting an entire paragraph. It's all in string format.
EDIT: I see that you deleted your comment, so I'm assuming you understand now. Good luck!
Carter Randall
3,311 PointsCarter Randall
3,311 PointsYep Thanks!