如何在Cocoa中获取应用程序菜单 [英] How i can get the Application Menu in Cocoa

查看:141
本文介绍了如何在Cocoa中获取应用程序菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得NSMenu或NSMenuItem的应用程序菜单(苹果菜单旁边的菜单栏中的一个)。它似乎是自动创建和独立的NSMenu我通过NSApplication setMainMenu设置。

How can i get the NSMenu or NSMenuItem for the application menu (the one in the menu bar next to the apple menu). It seems to be automatically created and independent from the NSMenu i set via NSApplication setMainMenu.

顺便说一句:我建立我的完整的应用程序没有XCode,所以请不要InterfaceBuilder

By the way: I'm building my complete application without XCode, so please no InterfaceBuilder tips.

PS:MacOSX 10.5

PS: MacOSX 10.5

推荐答案

可以使用NSApplication的mainMenu访问菜单:

Without IB, you can access the menu using the NSApplication's mainMenu:

NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];
NSMenu *appMenu = [[mainMenu itemAtIndex:0] submenu];

for (NSMenuItem *item in [appMenu itemArray]) {
    NSLog(@"%@", [item title]);
}

这篇关于如何在Cocoa中获取应用程序菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆