Cocoa button won't display image

Posted by A Mann on Stack Overflow See other posts from Stack Overflow or by A Mann
Published on 2010-06-16T16:15:13Z Indexed on 2010/06/16 17:32 UTC
Read the original article Hit count: 177

Filed under:
|

Just started exploring Cocoa so pretty much a total noob.

I've written a very simple game. Set it up in Interface Builder and got it working fine.

It contains a number of buttons and I'm now trying to get the buttons to display images.

To start with I'm trying to get an image displayed on just one of the buttons which is called tile0 .

The image file (it's nothing but a green square at the moment, but I'm just trying to get that working before I attempt anything more exotic) is sitting in the same directory as the class file which controls the game.

I have the following code sitting in my wakeFromNib method:

 NSString *myImageFileName = [[NSString alloc] init];
 myImageFileName = @"greenImage.jpg";
 NSImage *myImage = [[NSImage alloc] initByReferencingFile:myImageFileName];
 [tile0 setImage: myImage];

Trouble is, the game runs fine, but the image isn't appearing on my button.

Is there someone who could kindly tell me if I'm doing something obviously wrong?

Many Thanks.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa