I’m new to programming in general and currently trying to get a foot
into Objective-C. Like to write my first app for the iPhone, should
be a simple Golf app (for now). You enter your holes played and
strokes needed on the green and the app tells you what your average is.
When it comes to displaying the result in an UITextField I get lost.
I thought the ollowing code would work but the result is not showing:
- (IBAction)calcNow(id)sender
{
int holes = [[holesField text] intValue];
int strokes = [[strokesField text] intValue];
double result = strokes / holes;
[averageField setText:result];
}
Note:
The book I am reading tells me that a number, entered in an UITextField
must be converted before I’m able to work with the value as a number.
I think this will do it:
[[holesField text] intValue];
Is this correct?
Thanks for your help!
All you have to do is use:
Because setText: uses a
NSStringclass as message.