为什么 Xcode 给出这些错误?
我得到的错误是 Xcode 说 3 things are un-declared(见下图) alt text http://snapplr.com/snap/ks4h
但在头文件中我已经声明了它们(见下图)
alt text http://snapplr.com/snap/htmb
为什么我得到当我声明这些错误时。
完整代码:
头文件。
#import <Foundation/Foundation.h>
@interface HotKeyController : NSObject {
IBOutlet NSButton *cmdHK;
IBOutlet NSButton *ctrHK;
IBOutlet NSButton *optHK;
IBOutlet NSPopUpButton *keyHK;
IBOutlet NSWindow *window;
IBOutlet NSWindow *searchWindow;
IBOutlet NSWindow *entryWindow;
}
@end
实施文件
#import "HotKeyController.h"
#include <Carbon/Carbon.h>
@implementation HotKeyController
OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData)
{
EventHotKeyID hkCom;
GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkCom),NULL,&hkCom);
int l = hkCom.id;
switch (l) {
case 1: [window makeKeyAndOrderFront:NSApp];
break;
case 2: [searchWindow makeKeyAndOrderFront:nil];
break;
case 3: [entryWindow makeKeyAndOrderFront:nil];
break;
}
return noErr;
}
- (void)awakeFromNib
{
//Register the Hotkeys
EventHotKeyRef gMyHotKeyRef;
EventHotKeyID gMyHotKeyID;
EventTypeSpec eventType;
eventType.eventClass=kEventClassKeyboard;
eventType.eventKind=kEventHotKeyPressed;
InstallApplicationEventHandler(&MyHotKeyHandler,1,&eventType,pl,NULL);
gMyHotKeyID.signature='htk1';
gMyHotKeyID.id=1;
if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowMain"]!=-999) {
RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowMain"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowMainModifier"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
}
gMyHotKeyID.signature='htk2';
gMyHotKeyID.id=2;
if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowSearch"]!=-999) {
RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowSearch"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowSearchModifier"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
}
gMyHotKeyID.signature='htk3';
gMyHotKeyID.id=3;
if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowEntry"]!=-999) {
RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowEntry"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowEntryModifiers"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
}
}
@end
The error I get is Xcode saying 3 things are un-declared (see below picture)
alt text http://snapplr.com/snap/ks4h
But in the Header File I have declared them (see below picture)
alt text http://snapplr.com/snap/htmb
Why I am getting these errors when I have declared them.
The Full Code:
Header File.
#import <Foundation/Foundation.h>
@interface HotKeyController : NSObject {
IBOutlet NSButton *cmdHK;
IBOutlet NSButton *ctrHK;
IBOutlet NSButton *optHK;
IBOutlet NSPopUpButton *keyHK;
IBOutlet NSWindow *window;
IBOutlet NSWindow *searchWindow;
IBOutlet NSWindow *entryWindow;
}
@end
Implementation File
#import "HotKeyController.h"
#include <Carbon/Carbon.h>
@implementation HotKeyController
OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData)
{
EventHotKeyID hkCom;
GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkCom),NULL,&hkCom);
int l = hkCom.id;
switch (l) {
case 1: [window makeKeyAndOrderFront:NSApp];
break;
case 2: [searchWindow makeKeyAndOrderFront:nil];
break;
case 3: [entryWindow makeKeyAndOrderFront:nil];
break;
}
return noErr;
}
- (void)awakeFromNib
{
//Register the Hotkeys
EventHotKeyRef gMyHotKeyRef;
EventHotKeyID gMyHotKeyID;
EventTypeSpec eventType;
eventType.eventClass=kEventClassKeyboard;
eventType.eventKind=kEventHotKeyPressed;
InstallApplicationEventHandler(&MyHotKeyHandler,1,&eventType,pl,NULL);
gMyHotKeyID.signature='htk1';
gMyHotKeyID.id=1;
if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowMain"]!=-999) {
RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowMain"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowMainModifier"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
}
gMyHotKeyID.signature='htk2';
gMyHotKeyID.id=2;
if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowSearch"]!=-999) {
RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowSearch"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowSearchModifier"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
}
gMyHotKeyID.signature='htk3';
gMyHotKeyID.id=3;
if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowEntry"]!=-999) {
RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowEntry"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyShowEntryModifiers"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
}
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为这些行位于函数中,而不是 HotKeyController 类的方法中。 将函数放在哪里(是否在
@implementation
内)并不重要; 它仍然是一个函数,而不是一个方法。您可以在创建事件处理程序时进行设置。 事实上,您已经将其设置为“
pl
”,无论它是什么。Because those lines are in a function, not in a method of the HotKeyController class. It doesn't matter where you put the function (inside
@implementation
or not); it's still a function, not a method.You set that when you create the event handler. In fact, you're already setting it to “
pl
”, whatever that is.您必须显示更多文件才能确定。 您是否正确导入了头文件? 你保存了头文件吗?
尝试插入显式的 self-> 参考,您可能会收到更具启发性的错误消息。
另外,尝试预处理实现文件(在“构建”菜单中),这可能会揭示为什么找不到 ivar。
You would have to show more of the file to be sure. Are you properly importing the header file? Have you saved the header file?
Try inserting the explicit self-> references and you might get a more revealing error message.
Also, try preprocessing the implementation file (in the Build menu) and that might reveal why the ivar isn't being found.
NSWindow 没有在 Foundation 框架中定义,
您必须导入正确的标头、ApplicationKit 或 Cocoa。
NSWindow is not defined in the Foundation framework,
you must import the right headers, ApplicationKit or Cocoa.