我有一小段程序在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
在檢查器面板中檢查圖像的目標成員資格 –