Grr! Accessing a function in a separate file.

Discussion in 'Mac Programming' started by Jeremy1026, Mar 8, 2009.

  1. macrumors 68000

    Joined:
    Nov 3, 2007
    #1
    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.
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Do you have change declared in your GameView.h?
    Code:
    @interface GameView : ??? {
    }
    - (void) change;
    @end
     
  3. thread starter macrumors 68000

    Joined:
    Nov 3, 2007
    #3
    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.
     
  4. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    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
     
  5. thread starter macrumors 68000

    Joined:
    Nov 3, 2007
    #5
    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.
     
  6. macrumors newbie

    Joined:
    Jan 7, 2009
    #6
    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.
     

Share This Page