Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,216
1,030
MainView.h

Code:
#import "GameView.h"

@interface MainScreen : NSView {
	
	GameView *gmView;
	
}

MainView.m

Code:
[gmView change];

GameView.m

Code:
- (void) change { Lala


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

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

into MainView.m, and removing the line from MainView.h, same result, nothing happened.
 
Do you have change declared in your GameView.h?
Code:
@interface GameView : ??? {
}
- (void) change;
@end

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

Code:
#import <Cocoa/Cocoa.h>

@interface GameView : NSView {

	
	
}

- (void) change;

What's weird is, there are no errors or warnings.
 
What evidence do you have that the line:
Code:
[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
 
What evidence do you have that the line:
Code:
[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
Code:
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.
 
Ok, I changed to
Code:
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 do
Code:
gmView = [[GameView alloc] init];
or use whatever special initializer you might have set up for it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.