gpt4 book ai didi

objective-c - 为什么 Xcode 给出这些错误?

转载 作者:行者123 更新时间:2023-12-03 17:28:18 24 4
gpt4 key购买 nike

我得到的错误是 Xcode 说 3 件事未声明(见下图) 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 …

But in the Header File I have declared them …

Why I am getting these errors when I have declared them [in the HotKeyController class].

因为这些行位于函数中,而不是 HotKeyController 类的方法中。将函数放在哪里(是否在 @implementation 内)并不重要;它仍然是一个函数,而不是一个方法。

How would I make the userData parameter point to my HotKeyController?

您可以在创建事件处理程序时进行设置。事实上,您已经将其设置为“pl”,无论它是什么。

关于objective-c - 为什么 Xcode 给出这些错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1072822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com