 |
 |
Problem: CurrencyConverter Tutorial
|
 |
|
 |
|
Mac Enthusiast
Join Date: Mar 2001
Location: North America
Status:
Offline
|
|
This is embarrassing, but I can't get my CurrencyConverter to work. It won't enter the method below under debug. It skips over and does not return the correct float number.
Code:
- (float)convertAmount float)amt atRate float)rate
{
return (amt * rate);
}
Is anyone familiar with this? I tried the usual debugging stuff but it never gives the right return value. It's got me worried that my programming skills are rusting...
It gets called from this method:
Code:
- (IBAction)convert id)sender
{
float rate, amt, total;
total = 10;
amt = [dollarField floatValue];
rate = [rateField floatValue];
// THIS LINE HERE!!!!!!
total = [converter convertAmount:amt atRate:rate];
//
[totalField setFloatValue:total];
[rateField selectText:self];
}
Thanks for any help.
John
[This message has been edited by SillyMonk (edited 04-07-2001).]
|
|
My life is my argument. --Albert Schweitzer
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Status:
Offline
|
|
I am having the same problem with the exact same line of code. I keep getting the message "converter undeclared (first use in this function)" when I build the app. I went back so many times through the tutorial to see if I missed something. I didn't.
I am sure it is one of those things that is so simple, but we don't see it. Any Cocoa experts give us a hand? Please?
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Are you including the Converter.h header file in ConverterController? This works fine for me:
ConverterController.m:
Code:
#import "ConverterController.h"
#import "Converter.h"
@implementation ConverterController
- (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];
}
- (void)awakeFromNib
{
[rateField selectText:self];
[[rateField window] makeKeyAndOrderFront:self];
}
@end
Converter.m:
Code:
#import "Converter.h"
@implementation Converter
- (float)convertAmount:(float)amt atRate:(float)rate
{
return (amt * rate);
}
@end
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Mar 2001
Location: North America
Status:
Offline
|
|
Angus_D,
thank you for the reply and code. I cut your code and pasted it into my files and I still get the same problem. It compiles fine, just no worky.
I wonder if it is a problem with my use of the Interface builder and the hooks it needs for calling different methods? There was some dragging and dropping that I may have "programmed" incorrectly in the tutorial.
thanks
John
|
|
My life is my argument. --Albert Schweitzer
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Status:
Offline
|
|
John,
I fixed the problem with mine. It seems that I forgot to add the converter outlet in IB. I added it and then declared "IBOutlet id converter;" in ConverterController.h
Now it builds fine. However it still won't run. When I try to run it, I get:
Code:
Apr 07 14:52:07 CurrencyConverter[748] *** -[ConverterController selectText:]: selector not recognized
Apr 07 14:52:07 CurrencyConverter[748] An uncaught exception was raised
Apr 07 14:52:07 CurrencyConverter[748] *** -[ConverterController selectText:]: selector not recognized
Apr 07 14:52:07 CurrencyConverter[748] *** Uncaught exception: <NSInvalidArgumentException> *** -[ConverterController selectText:]: selector not recognized
CurrencyConverter.app has exited with status 255.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Definitely sounds like you got some outlets wired up wrong. Check, check and doublecheck!
I can .tar.gz the source and put it on my iDisk if that would be useful, but it's probably best if you do it for yourself (for your own sake  ).
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2001
Location: Minneapolis, MN, USA
Status:
Offline
|
|
My first experience with this tutorial was not promising. I didn't get any compile errors, or errors when running the thing, but it did nothing!
I tried mucking with the build, but got nada.
Then, I started from scratch and did everything again; discovering that I hadn't really understood the instructions about outlets and connections!
It works perfectly now. The tutorial contains no errors. If you follow the instructions exactly, you'll get the right results. You'll also gain valuable experience in working with PB & IB!
Good luck...
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Mar 2001
Location: North America
Status:
Offline
|
|
Thanks everyone for the help.
Angus_D, thanks for the code offer. I really need to understand where I went wrong, but thanks.
dws, I think I messed up the IB stuff as you did. However you say that the tutorial has no errors. I cannot get the find "NSApplicationMain" example to work using the "definitions' setting as they suggest. It only works for me with "textual" option. Maybe my system is messed up <horrors!>
Scratch that last part...I just had to index a couple of more times and then it worked, although I don't know why....
Thanks again.
John
[This message has been edited by SillyMonk (edited 04-07-2001).]
|
|
My life is my argument. --Albert Schweitzer
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|