Xcode 完成无法识别我的变量的类型

发布于 2024-08-20 09:10:07 字数 599 浏览 9 评论 0原文

我正在创建一个对象:(

NSMenu *appMainMenu = [[NSMenu alloc] initWithTitle:@"MyApp"];

忽略我以编程方式创建此菜单而不是使用 Nib 文件的事实。我了解这样做的缺点)

菜单在菜单栏中正确显示。

但是,当我尝试调用任何实例方法时,例如:

 [appMainMenu addItemWithTitle:@"MyTitle" action:@selector(myaction:) keyEquivalent:@"t"];

XCode 提供了一些完成,但似乎没有来自 NSMenu。
我已经尝试过这两种

#import <AppKit/AppKit.h> and #import <AppKit/NSMenu.h>

实例方法肯定存在于 NSMenu.h 中,正如我所说,它安装了我的菜单。它只是不安装菜单项。再加上缺乏完成,让我认为我的 appMainMenu 没有被识别为 NSMenu 对象,即使它显然是有效的。

我错过了什么明显的事情?

I'm creating an object with:

NSMenu *appMainMenu = [[NSMenu alloc] initWithTitle:@"MyApp"];

(Ignore the fact I'm creating this menu programmatically and not using a Nib File. I understand the disadvantages of doing so)

The menu appears correctly in the menubar.

However, when I try to call any instance method such as:

 [appMainMenu addItemWithTitle:@"MyTitle" action:@selector(myaction:) keyEquivalent:@"t"];

XCode offer some completions, but none appear to come from NSMenu.
I've tried both

#import <AppKit/AppKit.h> and #import <AppKit/NSMenu.h>

The instance methods are certainly there in NSMenu.h, and as I said, it installs my menu. It just doesn't install the menu item. That plus the lack of completions makes me think that my appMainMenu is not being recognized as a NSMenu object, even though it's obviously valid.

What obvious thing am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

伤感在游骋 2024-08-27 09:10:07

我正在创建一个对象:

NSMenu *appMainMenu = [[NSMenu alloc] initWithTitle:@"MyApp"];

你应该 [NSMenu menuZone] 分配它。

(它与 10.6.1 中的默认区域相同,但只要文档说您应该使用 [NSMenu menuZone],您可能应该使用 [NSMenu menuZone].)

但是,当我尝试调用任何实例方法时,例如:

[appMainMenu addItemWithTitle:@"MyTitle" 操作:@selector(myaction:) keyEquivalent:@"t"];

XCode 提供了一些补全,但似乎没有一个来自 NSMenu。

首先,它是 Xcode,带有小写的 c。

尝试保存。有时 Xcode 直到我保存文件才意识到我已经创建了一个变量,从而促使它重建任何完成的内容。

I'm creating an object with:

NSMenu *appMainMenu = [[NSMenu alloc] initWithTitle:@"MyApp"];

You should allocate it from [NSMenu menuZone].

(It's the same zone as the default as of 10.6.1, but as long as the documentation says you should use [NSMenu menuZone], you probably should use [NSMenu menuZone].)

However, when I try to call any instance method such as:

[appMainMenu addItemWithTitle:@"MyTitle" action:@selector(myaction:) keyEquivalent:@"t"];

XCode offer some completions, but none appear to come from NSMenu.

First, it's Xcode, with a lowercase c.

Try saving. Sometimes Xcode doesn't realize I've created a variable until I save the file, thereby provoking it to rebuild whatever the completions are coming from.

末が日狂欢 2024-08-27 09:10:07

我首先创建一个空的主菜单,然后将菜单项附加到其中:-

// I am also entirely unsure about the difference between
// using AppKit directly vs the Cocoa framework
#import <cocoa/cocoa.h>

// create an empty main menu and set it as the apps main menu
[NSApp setMainMenu:[[NSMenu alloc] init]];
// The first (sub)menu of the app menu is always the app menu and is named automatically
NSMenu* appMenu = [[NSMenu alloc] initWithTitle:@""];
// Now, add an about entry
[appMenu addItemWithTitle:@"About MyApp" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];

这对我有用。

I start by creating an empty main menu, then attaching the menu items to it :-

// I am also entirely unsure about the difference between
// using AppKit directly vs the Cocoa framework
#import <cocoa/cocoa.h>

// create an empty main menu and set it as the apps main menu
[NSApp setMainMenu:[[NSMenu alloc] init]];
// The first (sub)menu of the app menu is always the app menu and is named automatically
NSMenu* appMenu = [[NSMenu alloc] initWithTitle:@""];
// Now, add an about entry
[appMenu addItemWithTitle:@"About MyApp" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];

This works for me.

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