Plz help me to fix a bug.

Discussion in 'Mac Programming' started by mac@newlife, Jul 18, 2005.

  1. mac@newlife macrumors newbie

    mac@newlife

    Joined:
    Jul 5, 2005
    #1
    Hi Folks, I just followed to the tutorial of Apple, and I got an error that
    "/ConverterController.m:12: error: 'converter' undeclared (first use in this function)" Can anyone help me?

    Converter.h
    --------------------------------
    #import <Cocoa/Cocoa.h>

    @interface Converter : NSObject
    {
    }

    - (float)convertAmount:(float)amt atRate:(float)rate;
    @end

    Converter.m
    -------------------------------
    #import "Converter.h"

    @implementation Converter

    - (float)convertAmount:(float)amt atRate:(float)rate;
    {
    return (amt * rate);
    }

    @end

    ConverterController.h
    --------------------------------------------------
    #import <Cocoa/Cocoa.h>

    @interface ConverterController : NSObject
    {
    IBOutlet NSTextField *dollarField;
    IBOutlet NSTextField *rateField;
    IBOutlet NSTextField *totalField;
    }
    - (IBAction)convert:(id)sender;
    @end

    ConverterController.m
    -------------------------------------------------
    #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 window] makeKeyAndOrderFront:self];
    [rateField selectText:self];
    }

    @end
     
  2. mac@newlife thread starter macrumors newbie

    mac@newlife

    Joined:
    Jul 5, 2005
  3. ITASOR macrumors 601

    ITASOR

    Joined:
    Mar 20, 2005
    Location:
    Oneida, NY
    #3
    Put the [CODE ] and [/CODE ] tags around your code (without the space after each code in my example) and it will not create the smiley expressions and therefore be easier to read.
     
  4. WildCowboy Administrator/Editor

    WildCowboy

    Staff Member

    Joined:
    Jan 20, 2005
  5. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #5
    You need to add an outlet called "converter" to the ConverterController class in Interface Builder, and connect it to the Converter object that you instantiated. From the tutorial:

    You'll also need to add the following code to ConverterController.h under the text field declarations:

    Code:
    IBOutlet id converter;
     
  6. mac@newlife thread starter macrumors newbie

    mac@newlife

    Joined:
    Jul 5, 2005
    #6
    Thanks a lot! HexMonkey. That's work. U are so great. :)
     

Share This Page