NSImage setImage?

Discussion in 'Mac Programming' started by Blakeasd, Feb 4, 2011.

  1. Blakeasd macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    Hello
    I am having some problems giving NSImage a file. Can someone tell me why I am getting this error?
    'NSImage' may not respond to '-setImage:'

    Here is my code:

    Code:
    
    
    NSImage *left;
    [left setImage:[NSImage imageNamed:@"left.png"]];
    
    
    Does anyone know why it is giving me this warning?
    Help is appreciated
    Thanks
     
  2. Comrade Yeti macrumors newbie

    Joined:
    Nov 3, 2010
    #2
    Because there is no "setImage" message than can be sent to NSImage.

    You simply want

    Code:
    NSImage* left = [NSImage imageNamed:@"left.png"];
     
  3. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #3
    "left" is an uninitialised variable of type NSImage*.
    You try to send a message to an uninitialised variable.
    The compiler warns you because this is going to crash when you run the code.

    I'd think about how I would initialise the variable.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Maybe you intended 'left' to be an NSImageView.
    It has a setImage: method.
     
  5. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #5
    Really? Is your compiler that observant? I have not noticed that kind of warning from mine. (Then again, I have probably not made that mistake in a very long time.)
     

Share This Page