我对此非常陌生,但这里有:
我想在我的应用程序中按一个按钮,并有一个图像显示(我打算从相机读取它,但是首先,我将打开.TIF文件。)但是,在界面构建器中,我可以在NSObject对象中创建按钮,但是文献让我觉得我需要创建一个NSView对象来显示文件。问题是,当我这样做时,NSObject对象似乎与NSView对象没有对话。我想做的事情如下:
NSString *inFilePath;
inFilePath = @"/Volumes/Data/Temp/Smiles.tiff";
NSImage *TestImage = [[NSImage alloc] initWithContentsOfFile:inFilePath];
[MyView setImage:TestImage];
在这里,MyView是NSView对象。我收到警告,MyView可能无法响应setImage。我试图在NSObject对象中定义一个IBOutlet,虽然我可以在界面构建器中连接它,但是控制台给了我错误:
无法识别的选择器发送到类0x1e080
因此,目前尚不清楚下一步是什么。是否有一种简单的方法可以让两个不同的对象相互“交谈”?
谢谢
你想要一个 NSImageView
目的。在Interface Builder库中,这称为 形象好,但您可以配置它,使其没有挡板。
NSImageView
是。的子类 NSView
针对显示图像进行了优化。
在标题(.h)文件中,您应该具有以下内容:
@interface MyController : NSObject
{
//this declares an outlet so you can hook up the
//image view in Interface Builder
IBOutlet NSImageView* imageView;
}
@end
在您的实现(.m)文件中:
@implementation MyController
//called once the nib is loaded and all outlets are available
- (void)awakeFromNib
{
NSString *inFilePath = @"/Volumes/Data/Temp/Smiles.tiff";
NSImage *testImage = [[NSImage alloc] initWithContentsOfFile:inFilePath];
#if !__has_feature(objc_arc)
[testImage autorelease];
#endif
//imageView is your outlet
[imageView setImage:testImage];
}
@end
在Interface Builder中你应该连接 imageView
你的班级出口指向 NSImageView
你放在你的视野上。
你想要一个 NSImageView
目的。在Interface Builder库中,这称为 形象好,但您可以配置它,使其没有挡板。
NSImageView
是。的子类 NSView
针对显示图像进行了优化。
在标题(.h)文件中,您应该具有以下内容:
@interface MyController : NSObject
{
//this declares an outlet so you can hook up the
//image view in Interface Builder
IBOutlet NSImageView* imageView;
}
@end
在您的实现(.m)文件中:
@implementation MyController
//called once the nib is loaded and all outlets are available
- (void)awakeFromNib
{
NSString *inFilePath = @"/Volumes/Data/Temp/Smiles.tiff";
NSImage *testImage = [[NSImage alloc] initWithContentsOfFile:inFilePath];
#if !__has_feature(objc_arc)
[testImage autorelease];
#endif
//imageView is your outlet
[imageView setImage:testImage];
}
@end
在Interface Builder中你应该连接 imageView
你的班级出口指向 NSImageView
你放在你的视野上。