简体   繁体   中英

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 its 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.

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.

替代文字替代文字

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM