tags:

views:

52

answers:

4

Guys, I have two classes AppController and Robot.

AppController.h
#import <Cocoa/Cocoa.h>
#import "Robot.h"

@interface AppController : NSObject {

 Robot *myRobot;

}
- (IBAction)initPort:(id)sender;


AppController.m

#import "AppController.h"
@implementation AppController


- (IBAction)initPort:(id)sender
{
 [myRobot nothingDo];
}
@end

Robot.h

#import <Cocoa/Cocoa.h>
@interface Robot : NSObject {

}
-(void)nothingToDo:(id)sender;


Robot.m
#import "Robot.h"

@implementation Robot

-(void)nothingToDo:(id)sender
{
    NSLog(@"bla-bla-bla");
}

When I'm trying to run I see 'Robot' may not respond to '-nothingToDo' and -(void)nothingToDo is not being performed. What 's wrong?

+3  A: 

The colons in an Objective-C method is significant. Try

[myRobot nothingToDo:sender];

instead.

KennyTM
Yeah, it helps:)))) But, I didn't know about colon before. Thanks
moldov
A: 

When compiling AppController.m the compiler is not aware of private -nothingToDo method since it does not appear in Robot.h. This is why a warning is issued.

Actually, this method doesn't exist, only -nothingToDo: (note the : meaning an argument is needed). This is why the method is not called.

mouviciel
An argument for downvoting?
mouviciel
You were downvoted because the method is declared in the header correctly and the real problem is that the question is sending the method `nothingDo` instead of `nothignToDo:`, a case of mistyping method name AND missing the sender parameter. The warning is true, robot doesn't respond to those messages.
Jasarien
Let's leave the typo out of discussion, it's easy to fix. Anyway, `-nothingToDo` does not appear in the header file, only `-nothingToDo:`
mouviciel
Yeah, it helps:)))) But, I didn't know about colon before. Thanks
moldov
A: 

Start by making sure myRobot references a valid Robot object.

ahmadabdolkader
+2  A: 

You're sending the message nothingDo, and not nothingToDo (might be just a typo).

Furthermore, you forgot the sender parameter.

Try this:

- (IBAction)initPort:(id)sender
{
   [myRobot nothingToDo:sender];
}

This should work, provided myRobot is a properly allocated and initializedRobot object.

gclj5
Yeah, it helps:)))) But, I didn't know about colon before. Thanks
moldov