- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Apple 的文档说:
All of an application’s menus in the menu bar are owned by one NSMenu instance that’s created by the application when it starts up. You can retrieve this main menu with the NSApplication method mainMenu.
我的委托(delegate)类中有以下内容来获取应用程序的菜单:
- (void)applicationDidFinishLaunching:(NSNotification *)notification{
NSMenu *mainMenu=[[NSApplication sharedApplication] mainMenu];
}
为什么mainMenu
为零?我是不是在错误的时间调用了它?将 [[NSApplication sharedApplication] mainMenu]
放入我的 View Controller 的 loadView
中也会返回 nil。
我想做的就是向应用程序菜单栏添加项目。
最佳答案
代码返回 nil,因为关联的 Storyboard 没有应用程序场景/菜单栏。
使用 xcode 创建一个新的 Cocoa 应用程序项目为我构建了这一切,我只需要移植我的文件即可。上面的代码现在按预期返回 NSMenu。
关于macos - 为什么 NSApplication sharedApplication mainMenu 返回 nil ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41831912/
当我从 Xcode 在 Debug模式下运行应用程序时,它可以工作,但是当我在 Release模式下运行它时,它会在输出以下内容后崩溃: Unable to load nib file: MainMe
每次我创建任何类型的 cocoa 项目(基于文档,带有核心数据和/或聚光灯导入器)并打开 MainMenu.xib 时,我都会在对象选项板窗口右下角看到一个警告标志,表示窗口已关闭屏幕边界。为什么会这
我正在 Xcode 5.1 中处理一个新项目,并且我一直在使用 Interface Builder 来创建和绑定(bind)大部分布局。我自定义了默认的 MainMenu.xib 以包含我想要的菜单项
我需要以编程方式在 Winform 中的窗体上显示主菜单的子菜单。NΕΤ 应用程序(类 MainMenu 和 MenuItem)。 例如显示包含菜单项文件的所有项目的子菜单。 例如如果菜单项文本为 &
一种常见的 UI 模式是在状态栏中显示与当前所选菜单项相关的文本。 过去,我在 winforms 中实现了这一点,方法是创建一个扩展程序提供程序,该扩展程序提供程序添加一个字符串属性,其中包含要在状态
我需要一种方法来更改 Cocoa 应用程序中菜单栏 (MainMenu.xib) 中的字符串,以便根据我设置的区域设置动态呈现。我已经为不同的语言环境创建了 MainMenu.strings 文件。目
如何判断所有 MainMenu Nib 控件(主要是主窗口)何时已加载?我想在启动时在主窗口顶部显示一个工作表,但是当我将调用 beginSheet 放入 awakeFromNib 内部时,我收到错误
我有一个包含窗口的 Nib (winA.xib)。我的应用程序委托(delegate)包含一个名为 WinAController 的 NSWindowController 子类。 WinAContro
我正在尝试使用箭头键或通过 Controller 上的方向键使我的菜单可导航。到目前为止,我运气不好。 问题是:有人可以指导我如何使我的当前菜单或任何 libgdx 菜单键盘可访问吗? 我对某些东西有
每当我构建以下程序时,Form1 的大小都会缩小 20。(在某些情况下,我需要对表单进行更改,例如将 someLaggyControl1 移动到几个像素,但并非总是如此。这很奇怪。)表单使用 Main
在 MainMenu.xib 中,我可以删除 NSObjects 来创建类实例。这些对象被删除的垂直顺序是它们将被分配的顺序吗?我可以信赖它吗? 最佳答案 不,您不能依赖对象列出的顺序作为它们实例化的
我已经开始开发一些小型 Cocoa 应用程序。它工作得很好,但现在我想创建我自己的 MainMenu(不使用 XCode 创建的默认 MainMenu.xib)。 但是我遇到了一些障碍。首先,我添加两
已经asked before ,但似乎没有明确的(当前)答案。是否真的有可能构建一个带有主菜单的 Cocoa 应用程序,仅通过代码(没有 MainMenu.xib 等),这样它仍然会提交到应用商店时能
我不知道如何让 macOS Cocoa 应用程序的包管理适用于 Xcode 8、Swift 3。无论我做什么,我都会得到: Unable to load nib file: MainMenu, exi
当您创建新的 Cocoa 应用程序时,Xcode 会为您生成 MainMenu.xib,其中包含一组预定义的菜单项(文件、编辑、格式、 View 等)。 我做了一个非常简单的应用程序。我真的不需要菜单
对于 iOS (Cocoa Touch),可以转到 main.m 并将 UIApplicationMain(int argc, char *argv[], nil, nil) 中的第四个参数替换为类您
我搜索了更改 Compact Framework 的 MainMenu 控件背景颜色的解决方案,我发现的唯一答案是您需要创建自定义控件。有没有人有这方面的示例代码? 最佳答案 我做了一些类似的事情,我
我在 WinForm 中使用 MainMenu 控件(不是 MenuStrip)。在设计 View 中,我可以在文本字段中放置一个 &,它会显示下划线,但是当程序运行并且我按下 ALT 时,它不会出现
我正在将 iOS 应用程序移植到 OS X。我正在考虑使用 Apple 示例代码“AnimatedTableView”作为起点,但惊讶地发现它没有 NSApplicationDelegate。在 iO
在我完成编写应用程序后第二次尝试打开文件 MainMenu.xib 时重新打开项目: 无法打开文档“MainMenu.xib”。操作无法完成。 * -[__NSArrayM insertObject:
我是一名优秀的程序员,十分优秀!