문제

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

도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top