【发布时间】:2016-06-29 16:13:26
【问题描述】:
我正在编写一个使用最少 IB 的 Mac 应用程序——请参阅programatically create initial window of cocoa app (OS X)。
这是我的代码(通过 Xamarin/C#):
public override void DidFinishLaunching(NSNotification notification) {
// create and show a window, then . . .
NSMenu fileMenu = new NSMenu();
NSMenu appMenu = new NSMenu();
// add some items to both menus, then . . .
NSMenuItem file = new NSMenuItem("file");
file.Submenu = fileMenu;
NSMenuItem app = new NSMenuItem("app");
app.Submenu = appMenu;
NSMenu topLevelMenu = new NSMenu();
topLevelMenu.AddItem(app); // these two lines in
topLevelMenu.AddItem(file); // either order
NSApplication.SharedApplication.Menu = topLevelMenu; // incidentally, setting the MainMenu doesn't appear to do anything
}
}
奇怪的是只显示了我添加的第一个菜单项,并且它的标题更改为我的应用程序的名称。所以对于上面的代码,我只会看到应用程序菜单,标题为 MyAppName,但项目正确。如果我先添加文件 NSMenuItem,我会看到该菜单,其名称再次更改为我的应用程序名称,并且视图菜单根本不会显示。
我不介意更改标题;我想Apple希望始终显示活动应用程序的名称。但让我感到困扰的是,我无法显示其他菜单。
如何让我的所有菜单显示在屏幕顶部?
【问题讨论】:
-
fileMenu和appMenu缺少标题。
标签: cocoa xamarin appkit nsmenu nsmenuitem