Xcode 完成无法识别我的变量的类型
我正在创建一个对象:(
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你应该 从
[NSMenu menuZone]
分配它。(它与 10.6.1 中的默认区域相同,但只要文档说您应该使用
[NSMenu menuZone]
,您可能应该使用[NSMenu menuZone]
.)首先,它是 Xcode,带有小写的 c。
尝试保存。有时 Xcode 直到我保存文件才意识到我已经创建了一个变量,从而促使它重建任何完成的内容。
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]
.)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.
我首先创建一个空的主菜单,然后将菜单项附加到其中:-
这对我有用。
I start by creating an empty main menu, then attaching the menu items to it :-
This works for me.