before about a week ago, the only programming experience I ever had was high school
pascal, so I suppose I should warn all that this is a severe newbie question...
anyway, I wanted to get into cocoa development, seeing as how Apple had included all the developer tools in the box with X and whatnot... so I fired up CurrencyConverterTutorial.pdf and got to work.
I followed the tutorial verbatim (as far as I can tell -- I've checked over it a hundred times looking for what went wrong...) and now, whenever I debug/run a build of CurrencyConverter, it behaves in a way I don't understand.
The app has three fields, you know, being rateField, dollarField, and totalField. you enter your values in rateField and dollarField, which are then fed into ConverterController.m:
...
- (IBAction)convert
id)sender
{
float rate, amt, total;
amt = [dollarField floatValue];
rate = [rateField floatValue];
total = [converter convertAmount:amt atRate:rate];
[totalField setFloatValue:total];
[rateField selectText:self];
}
...
and then, when the "convert" button is activated in the app,
convert: is called:
...
- (float)convertAmount
float)amt atRate
float)rate;
...
in Interface Builder, the instance of
ConverterControlloer is connected to the three fields properly, targeting (from top to bottom)
rateField,
dollarField, and
totalField. the "convert" button is then, in turn, connected to the instance of
ConverterController, targeting the action
convert:. so much as I can tell, everything seems to be right so far.
back in Project Builder, editing
converter.m, we have:
...
- (float)convertAmount
float)amt atRate
float)rate
{
return (amt * rate);
}
...
so... it seems to me, that from what the code in the tutorial says, the app should work as so: enter a float value into the first field, which is put into the variable
rate; enter a float value into the second filed, which is put into the variable
amt; press the "convert" button, and
convert: returns a value
(amt * rate) which is put into the variable
total;
total is then, in turn, put into the third field.
but... it's not working for me. I enter the values "2" and "2," expecting a return of "4," but
no... I get "2" back, instead. hmmm....
I have pondered and poked at this thing for days upon days, and I'm at my wits' end. I hope someone can help me out here.
just in case, I'll include the
.hs and
.ms here so you can see what I'm working with:
ConverterController.h:
#import <Cocoa/Cocoa.h>
@interface ConverterController : NSObject
{
IBOutlet id converter;
IBOutlet id dollarField;
IBOutlet id rateField;
IBOutlet id totalField;
}
- (IBAction)convert
id)sender;
@end
ConverterController.m:
#import "ConverterController.h"
#import "Converter.h"
@implementation ConverterController
- (void)awakeFromNib
{
[[rateField window] makeKeyAndOrderFront:self];
[rateField selectText:self];
}
- (IBAction)convert
id)sender
{
float rate, amt, total;
amt = [dollarField floatValue];
rate = [rateField floatValue];
total = [converter convertAmount:amt atRate:rate];
[totalField setFloatValue:total];
[rateField selectText:self];
}
@end
Converter.h:
#import <Cocoa/Cocoa.h>
@interface Converter : NSObject
{
}
- (float)convertAmount
float)amt atRate
float)rate;
@end
Converter.m:
#import "Converter.h"
#import "ConverterController.h"
@implementation Converter
- (float)convertAmount
float)amt atRate
float)rate
{
return (amt * rate);
}
@end
Thanks, and I hope I'm not just being stupid...
------------------
[This message has been edited by rgoer (edited 04-21-2001).]