我得到的错误是 Xcode 说 3 件事未声明(见下图) alt text http://snapplr.com/snap/ks4h
但是在头文件中我已经声明了它们(见下图)
替代文字 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