我知道这必须是非常简单的事情,但我一生都无法弄清楚。我无法让 XCode 将 NSWindow 识别为 Objective-c 类。我有以下简单的代码:
HelloWorldAppDelegate.h
#import <Cocoa/Cocoa.h>
#import "EAGLView_mac.h"
@interface HelloWorldAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
EAGLView *glView;
}
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet EAGLView *glView;
@end
HelloWorldAppDelegate.m
#import "HelloWorldAppDelegate.h"
#import "EAGLView_mac.h"
@implementation HelloWorldAppDelegate
@synthesize window, glView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSRect frame = NSMakeRect(0, 0, 480, 320);
window = [[NSWindow alloc] initWithContentRect: frame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
//EAGL init code cut for brevity
[window setContent:glView];
[window makeKeyAndOrderFront:self];
}
@end
当我尝试编译 XCode 时抱怨 NSWindow 是接收器类型“void”而不是 Objective-c 类。当我输入代码时,也没有弹出任何自动完成功能。我在调用 NSWindow alloc 时收到一个实际错误,并且在其他两个调用“window”时收到警告,都抱怨 window 和/或 NSWindow 是接收器类型 void。它还抱怨找不到“setContent”和“makeKeyAndOrderFront”方法?我在某处缺少包含吗?