• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: A class "A" may not respond to a method of the class "B"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A class "A" may not respond to a method of the class "B"


  • Subject: Re: A class "A" may not respond to a method of the class "B"
  • From: Angel Manuel Mariblanca Gonzalez <email@hidden>
  • Date: Sun, 11 Jan 2009 12:57:48 +0100

Thank you all!
I didn't know that "self" only send messages to its own class. 
Ok, I'll follow your advices.
Bye and have a nice day!
El 11/01/2009, a las 2:31, Robert Tillyard escribió:

Hello,

That's because self (i.e. Controller) doesn't respond to showRandom, only RandomGenerator does.

You need to initialise and use the RandomGenerator class.

This is written in e-mail so probably has typo's
i.e.

Controller.h****************
#import <Cocoa/Cocoa.h>
#import <RandomGenerator.h>

@class RandomGenerator;

@interface Controller : NSObject 
{
    IBOutlet NSTextField *Text_field;

   RandomGenerator  *generator;
}
- (IBAction)showRandom:(id)sender;
@end
Controller.m****************
#import "Controller.h"
#import "RandomGenerator.h"
@implementation Controller

- (void)init
{
   if ((self = [super init])))
      {
// assuming you have an init method in Random Generator...
      generator = [[RandomGenerator] alloc] init];
      }
   return (self);
}

- (void)dealloc
{
[generator release];

[super dealloc]
}

- (IBAction)showRandom:(id)sender
{
[Text_field setIntValue:[generator randomNumber:115]];
}
@end

Regards, Rob.

On 11 Jan 2009, at 01:19, Angel Manuel Mariblanca Gonzalez wrote:

Hello!
I'm new developing for Mac, I'm starting, and I've got a problem with methods and class.
I have a class (RandomGenerator) that I created to be a random generator (obvious). This class have one method:

RandomGenerator.h****************
#import <Cocoa/Cocoa.h>
@interface RandomGenerator : NSObject 
{
int range;
}
- (int)  randomNumber: (int) withRange;
RandomGenerator.m****************
@implementation RandomGenerator
- (int) randomNumber: (int) withRange
{
if (range<1)
{
return 0;
} else 
{
int random_number=(random() % range)+1; 
return random_number;
}
}
@end


I have another class (Controller) to control the rest of the program. I tried to use the method randomNumber in this class, but doesn't work.

Controller.h****************
#import <Cocoa/Cocoa.h>
@interface Controller : NSObject 
{
    IBOutlet NSTextField *Text_field;
}
- (IBAction)showRandom:(id)sender;
@end
Controller.m****************
#import "Controller.h"
#import "RandomGenerator.h"
@implementation Controller
- (IBAction)showRandom:(id)sender
{
[Text_field setIntValue:[self randomNumber:115]];
}
@end

The message of error is: 
warning:'Controller' may not respond to '-randomNumber'.
(Messages without a matching method signature will be assumed to return 'id' and accept '...' as argument).

What could be the cause of this error? 
Thanks.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: A class "A" may not respond to a method of the class "B"
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >A class "A" may not respond to a method of the class "B" (From: Angel Manuel Mariblanca Gonzalez <email@hidden>)

  • Prev by Date: Re: A class "A" may not respond to a method of the class "B"
  • Next by Date: Re: A class "A" may not respond to a method of the class "B"
  • Previous by thread: Re: A class "A" may not respond to a method of the class "B"
  • Next by thread: Re: A class "A" may not respond to a method of the class "B"
  • Index(es):
    • Date
    • Thread