Domanda

I've the following problem:

I've added a NSImageView to my NSWindow. I set the controller of my Window as the file's owner. I can open my window, click on buttons. It works great. But when I try to set an icon to the ImageView, nothing happens because it's null.

What could be the reason it's null? I checked, and it's connected to the IBOutlet.

Thx

È stato utile?

Soluzione

Remember, Just connecting to the IBOutlet will not allocate the memory for given variable. Since you haven't allocated the memory it shows null.

So, do this first.

@property (nonatomic) IBOutlet NSImageView *imageView;

and then

@synthesize imageView = _imageView;

and then before you set the image you need to alloc and init the _imageView.

like,

_imageView = [NSImageView alloc] init];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top