开发者

Menu item doesn't show when creating menu in Interface Builder

In interface builder I added a menu item to the main menu. I can click on the menu and access i开发者_运维技巧ts contents, however the title of the menu item doesn't show when running the program.

The image shows the application and its menu on top and on the bottom is the application as it appears in IB. Notice that where the menu in IB has the "Calculate" menu option, the running application has in its menu a space instead.

Menu item doesn't show when creating menu in Interface Builder


In the menu bar, there is an NSMenuItem which contains an NSMenu. Both have a "Title" property. In Interface Builder, what you see in the menu bar is the title of the NSMenuItem. In the application, what you see is the title of the NSMenu. If the NSMenu's title is not set, then you'll just see an empty string, which is what you've shown in your screenshot.

Click on the Menu item in Interface Builder so that the attached menu shows up. You can then set the title.

Menu item doesn't show when creating menu in Interface Builder

Menu item doesn't show when creating menu in Interface Builder

Note that in Interface Builder, if you drag a Menu Item to the menu bar, you get an NSMenuItem without any NSMenu attached. I suspect that's what you've done. You can drag a Menu on top of the NSMenuItem to add a menu to it, and then you can set the menu's title correctly. If instead of dragging a Menu Item, however, you drag a Submenu Item, then the attached NSMenu is already present, and it automatically updates the title when you change the text in the menu bar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜