我有一小段程序在Image-well中显示图像。我正在测试,但屏幕上没有显示任何内容。欣赏任何人都可以提供帮助。无法在NSImageView中设置图像
.h文件中:
#import <Cocoa/Cocoa.h>
@interface TestAppDelegate : NSObject <NSApplicationDelegate>
{
IBOutlet NSImageView *myImageView;
}
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSImageView *myImageView;
@end
.m文件:
#import "TestAppDelegate.h"
@implementation TestAppDelegate
- (void)dealloc
{
[super dealloc];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString * filePath = @"haha.png"; // the pic file that I added into the project
NSImage * aImage = [NSImage imageNamed:filePath];
if(aImage)
{
NSLog(aImage.name);
NSLog(@"size %f %f",aImage.size.width,aImage.size.height);
//both of the NSLogs work but the Image-well shows blank
[myImageView setImage:aImage];
}
}
@end
这些类型的问题几乎都与'IBOutlet'连接没有连接有关。当你看到头文件中的'IOOutlet'是左边空白处填充的圆? – trojanfoe
或者,图像'haha.png'可能没有在项目中正确设置。用'NSLog(@“Image not set!”);''添加'else'子句到'if'语句。 – trojanfoe
在检查器面板中检查图像的目标成员资格 –