为什么 Xcode 给出这些错误?

发布于 2024-07-26 03:40:22 字数 2898 浏览 7 评论 0原文

我得到的错误是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜巴黎 2024-08-02 03:40:22

我得到的错误是 Xcode 说 3 件事未声明......

但是在头文件中我已经声明了它们......

为什么当我[在 HotKeyController 类中]声明它们时会收到这些错误。

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

如何使 userData 参数指向我的 HotKeyController?

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

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].

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.

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

You set that when you create the event handler. In fact, you're already setting it to “pl”, whatever that is.

我ぃ本無心為│何有愛 2024-08-02 03:40:22

您必须显示更多文件才能确定。 您是否正确导入了头文件? 你保存了头文件吗?

尝试插入显式的 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.

我也只是我 2024-08-02 03:40:22

NSWindow 没有在 Foundation 框架中定义,
您必须导入正确的标头、ApplicationKit 或 Cocoa。

NSWindow is not defined in the Foundation framework,
you must import the right headers, ApplicationKit or Cocoa.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文