在我的应用程序的主菜单中设置项目的标题

在我的应用程序的主菜单中设置项目的标题

本文介绍了在我的应用程序的主菜单中设置项目的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改可可应用主菜单中某些项目的标题.我尝试在IB内以及通过应用程序的applicationDidFinishLaunchingWithOptions:方法以编程方式设置它们.无论哪种方式,我的NSMenuItem对象的title属性都不会更改.但是,运行应用程序时,我的任何更改都没有反映在屏幕顶部的项目的实际标题中.

I am trying to change the titles of some of the items in my Cocoa app's main menu. I have tried setting them both within IB and also programmatically from my app's applicationDidFinishLaunchingWithOptions: method. Either way, the title property of my NSMenuItem object does change. But none of my changes are reflected in the actual title of the item at the top of the screen when the app is running.

任何人都可以解释发生了什么吗?而我该如何改变呢?

Can anyone explain what is going on? And how can I change this?

数据结构是IB设置的默认结构:

The data structure is the default one that IB sets up:

NSApplication *app = [NSApplication sharedApplication];
NSMenu *mainMenu = [app mainMenu];
NSArray *itemArray = [mainMenu itemArray];
NSMenuItem *firstItem = [itemArray objectAtIndex: 0];
NSMenu *submenu = [firstItem submenu];

我已经将firstItem和subMenu的标题属性更改为我想要的标题.但是默认值仍然会显示.

I have changed the title properties of both firstItem and subMenu to be my desired title. Yet the default one still shows.

推荐答案

重命名该项目即可.不过似乎太极端了.我仍然会对不太极端的解决方案感兴趣.

Renaming the project did it. Seems too extreme, though. I would still be interested in a less extreme solution.

这篇关于在我的应用程序的主菜单中设置项目的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 05:29