PDA

View Full Version : Grr! Accessing a function in a separate file.




Jeremy1026
Mar 8, 2009, 10:30 AM
MainView.h

#import "GameView.h"

@interface MainScreen : NSView {

GameView *gmView;

}

MainView.m

[gmView change];

GameView.m

- (void) change { Lala


What am I doing wrong. 'change' in GameView won't fire.

I also tried plopping
GameView *gmView = (GameView *)[NSApplication sharedApplication];

into MainView.m, and removing the line from MainView.h, same result, nothing happened.



dejo
Mar 8, 2009, 10:37 AM
Do you have change declared in your GameView.h?
@interface GameView : ??? {
}
- (void) change;
@end

Jeremy1026
Mar 8, 2009, 10:38 AM
Do you have change declared in your GameView.h?
@interface GameView : ??? {
}
- (void) change;
@end

Yes, I do, sorry, forgot my .h.

#import <Cocoa/Cocoa.h>

@interface GameView : NSView {



}

- (void) change;

What's weird is, there are no errors or warnings.

lee1210
Mar 8, 2009, 11:20 AM
What evidence do you have that the line:
[gmView change];
is being run at all?

What evidence do you have that the method change is not being called?

Have you put some debug in change and around the line that is passing that message to gmView? Have you ensured that gmView is not nil before the message change is passed to it?

-Lee

Jeremy1026
Mar 8, 2009, 11:29 AM
What evidence do you have that the line:
[gmView change];
is being run at all?

What evidence do you have that the method change is not being called?

Have you put some debug in change and around the line that is passing that message to gmView? Have you ensured that gmView is not nil before the message change is passed to it?

-Lee

Ok, I changed to if (gmView != nil) { [gmView change]; }
and added an NSLog in there, and nothing is being logged. So it looks like gmView is being considered nil. So I must be missing something in the declaration.

BorgCopyeditor
Mar 8, 2009, 11:52 AM
Ok, I changed to if (gmView != nil) { [gmView change]; }
and added an NSLog in there, and nothing is being logged. So it looks like gmView is being considered nil. So I must be missing something in the declaration.

Declaring gmView as a certain type does not create a GameView object. Implicit in Lee's suggestion about checking it for nil, I think, is a suggestion that you ensure that it has been initialized somewhere. Somewhere in the setup of your MainView, probably in awakeFromNib, you need to dogmView = [[GameView alloc] init];or use whatever special initializer you might have set up for it.