S.MacPherson S.MacPherson - 6 months ago 32
Objective-C Question

Numeric UITextField gives a WordNumeral in UILabel

Sorry in advance how I've written this..

In my Main.StoryBoard I have: UITextField (numeric), UILabel and UIButton.

I would like to:

Click UIButton

Take number from UITextField

Give corresponding 'word' and place in UILabel.

Lets say my numbers are in range from 1-9.

I'm having trouble linking the numbers with words and placing into the UILabel.

Is it best to use an NSArray or perhaps a Case Switch?


int num = [self.stringEntry.text intValue];

THEN... included NSArray of numbers and words correctly.

self.numberOneList = numberOneArray

self.wordOneList = wordOneArray

if (num <= 0 || num >= 10) {

self.wordLabel.text = @"Try a number between 1 and 9";

} else{

// what would I type here?


You can use NSDictionary in this case. Keys can be numbers (0-9) and values can be respected word. Then just take the value from the textfield and check it against the dictionary using valueForKey:.