NSStatusItem 菜单中的 VoiceOver 错误
我在使用 VoiceOver 时遇到了以下错误。我是 Cocoa 编程的新手,所以我很好奇我是否做错了什么,或者是否有其他方法可以做到这一点。以下代码在菜单栏上放置一个图标,并有一个包含 1 项的菜单。
当您打开 VoiceOver(命令-F5)并单击图标时,它会告诉您:“菜单(1 项)”。然而,第二次(有时是第三次)及之后,即使菜单没有改变,它也会显示“菜单(0 项)”。
#import <Cocoa/Cocoa.h>
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSStatusItem *status_item;
NSMenu *menu;
// The application needs a main menu to run
NSMenu *mainmenu = [[NSMenu alloc] init];
[[NSApplication sharedApplication] setMainMenu:mainmenu];
menu = [[NSMenu alloc] init];
NSMenuItem *menuitem = [[NSMenuItem alloc] initWithTitle:@"Empty" action:nil keyEquivalent:@""];
[menu addItem:menuitem];
status_item = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
NSImage *image = [[NSImage alloc] initWithContentsOfFile: @"/Library/Widgets/iTunes.wdgt/Images/repeat_one.png"];
[status_item setImage:image];
[status_item setMenu:menu];
[NSApp run];
[pool drain];
return 0;
}
您可以通过以下方式编译并运行它:
gcc -o menubar -Wno-import main.m -lobjc -framework Cocoa && ./menubar
我在 Snow Leopard 和 Lion 上都看到了这种行为。知道有什么吗?
谢谢!
I've run into the following bug using VoiceOver. I'm new to Cocoa programming, so I'm curious if I am doing something wrong, or if there is another way to do this. The following code puts an icon on the menubar, and has a menu with 1 item.
When you turn on VoiceOver (command-F5) and click on the icon, it tells you: "menu (1 items)". However, the second (or sometimes third) time and after, it says "menu (0 items)" even though the menu has not changed.
#import <Cocoa/Cocoa.h>
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSStatusItem *status_item;
NSMenu *menu;
// The application needs a main menu to run
NSMenu *mainmenu = [[NSMenu alloc] init];
[[NSApplication sharedApplication] setMainMenu:mainmenu];
menu = [[NSMenu alloc] init];
NSMenuItem *menuitem = [[NSMenuItem alloc] initWithTitle:@"Empty" action:nil keyEquivalent:@""];
[menu addItem:menuitem];
status_item = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
NSImage *image = [[NSImage alloc] initWithContentsOfFile: @"/Library/Widgets/iTunes.wdgt/Images/repeat_one.png"];
[status_item setImage:image];
[status_item setMenu:menu];
[NSApp run];
[pool drain];
return 0;
}
You can compile and run this via:
gcc -o menubar -Wno-import main.m -lobjc -framework Cocoa && ./menubar
I see this behaviour on both Snow Leopard and Lion. Any idea what gives?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论