I am trying to set image for an NSImageView instance object in a Cocoa project. My code looks like this:
itemTableCellView * xx = [tableView makeViewWithIdentifier:@"MainCell" owner:self];
xx.label.stringValue = [tempCi simpleTxt];
xx.img = [[NSImageView alloc]initWithFrame:CGRectMake(48, 48, 48, 48)]];
NSImage * localimage = [NSImage imageNamed:@"menubar icon"];
[xx.img setImage:localImage];
return xx;
The variable img
is of type NSImageView. The variable localImage
loads the correct image, I have checked it in the log. The variable lable
is initialized correctly and gets the right value
I just keep on getting empty NSImageViews in my app.
Your NSImageView
is initialized with no size (it's frame equals NSZeroRect
), also you don't add the image view to any subview.