这很神秘,而且超出我的理解。我尝试将NSImage分配给NSImageView。
func changePreviewImage() {
preview.image = grayness.image
print ("THERE IS \(grayness.image?.debugDescription ?? "NO") \(preview.image?.debugDescription ?? "NO IMAGE, BUT WHY???")")
preview.needsDisplay = true
}
我有一个输出说grayness.image
存在,但是分配后的preview.image
总是nil
。
THERE IS <NSImage 0x600001797600 Name=NSAdvanced Size={32, 32} Reps=(
"NSISIconImageRep 0x60000178e400 Size={32, 32} ColorSpace=Generic RGB colorspace BPS=0 Pixels=32x32 Alpha=NO AppearanceName=NSAppearanceNameAqua",
"NSISIconImageRep 0x60000178c740 Size={32, 32} ColorSpace=Generic RGB colorspace BPS=0 Pixels=32x32 Alpha=NO AppearanceName=NSAppearanceNameDarkAqua",
..... (all representations of an image)
)> NO IMAGE, BUT WHY???
这是怎么回事?
答案 0 :(得分:1)
问题在于NSImageView是作为一个简单的NSView创建的,并且稍后在IB Inspector中更改了类。当我删除旧的并重新创建时,NSImageView分配可以正常工作。