I have a document-based app, with separate View and Window menus in the main menu. The app uses .xib files, not storyboards.
Trouble is, both menus show duplicate items. I have customized both of them in the Interface Builder. My NSDocument implementation validates needed menu items, but it can't catch the automatically added ones. Even changing the top-menu titles won't affect the default items they are receiving.
Where can I find a setting, which determines which menu will get which items? I've searched intensely and gone through every file in my project, but either can't remember or can't search the correct words to find the solution.
Any help or hints would be appreciated.
Is it possible you originally created the View menu by copying the Window menu? That could explain the duplication. If you control-click the xib in Xcode and select Open As -> Source Code you will see the plist data. Search for systemMenu:
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
If your View menu has the systemMenu="window" parameter, try deleting it.
Related
I recently updated to Xcode 11 and some of its user interface changed. in older version of Xcode there was options of accessing files in assistant editor using automatic or manual. but in this version of Xcode I can't see any manual option in assistant editor. so I am not able to add IBOutlet and IBAction methods to particular storyboard.
so can anyone tell me how to add these actions and outlets, that would be great help. thanks
By pressing the above button, Xcode will split the view and allow you to select a custom file using the file tree at the top.
You are correct.
The Manual option is no longer visible. You can still achieve the same result by doing a quick open using Cmd+Shift+O then type the name of any file you want to open. Press the Alt key and the file will open in the Assistant Editor Window.
As others have noted the new add editor button allows you to add new editors and open files into them. You could file a bug report but you may want to consider that you're likely to get a "works as designed" type of reply.
You can always change or add new keyboard shortcuts to get the behavior you want by viewing the preferences key bindings area and search for the command you want to shortcut.
Note
You can still ctrl+drag from storyboard to the class by the Adjust
Editor button in the upper right of the storyboard. Then just select
Assistant Editor on the list. After which you can make IBOutlets/IBActions.
open your storyboard, hold option key and select the file you want
In the documentation outline of storyboard, try to choose the "correct" item, which you want to set up outlet connections. Say you want to set up an outlet connection for cell of table/collection view.
View Controller > Collection View > Cell > Content View > Image View.
Try to select Cell, "Content View" or "Image View", then check the jump bar of assistant editor, you're probably able to switch to the .swift file you want.
Reference
In decarbonizing I have now come to creating a menubar programmatically using NSMenu.
Carbon seems to be so nice to add standard items to the application menu: Services, Hide app, Hide Others, Show All, Quit app,
and they are even added using the user’s Preferred Language setting in System Preferences’s Language & Region,
so in German Hide Others is added as Andere ausblenden.
I only had to add the About and Preferences items.
However, it seems that in Cocoa I have to add these standard items myself,
but how can I find out what Hide Others is called in the user’s Preferred Language ?
And what is the Cocoa equivalent of CreateStandardWindowMenu ?
If you have Xcode create a new Cocoa application project, it will make a MainMenu.xib that you can examine. It looks like "Hide Others", "Quit" etc. are just menu items with particular actions assigned, but "Services" seems to have some special magic. Even if you don't want to present a whole menu bar from a nib, you could load it from a nib and then pick out certain menu items and move them to another menu, rename them or whatever. Though I'm not sure I understand what you're trying to accomplish. Even if you don't want to localize, you can use a nib.
To address the last part of your revised question, the NSApplication object has a windowsMenu property, i.e., you could create a menu and say [NSApp setWindowsMenu: myMenu]. But I don't know if that adds items like Bring All to Front or if you must create those yourself.
Long time iOS developer who's dipping his toes in the macOS world. Just trying to better understand how Mac apps work.
For non-storyboard applications based on a XIB, the template creates a default xib and inside is the application's main menu.
However, if I delete that XIB, then create a new one, how do I set up a menu to be the application's main menu? It seems to ignore whatever I create. Plus, when I add one, the graphic looks different than the original; here it's stacked vertically whereas the original had them stacked horizontally.
So, how can you create a second xib (in case you deleted the first one) and replace the main menu in it?
You have to do two steps to change the main menu to a menu in another XIB file:
Change the Main Interface in Deployment Info in the General tab of the Target of your application to the new XIB file.
Open the source code of the new XIB file and search for your new Main Menu. This is a XML tag named menu. Add an attribute named systemMenu with the value main to it. This should look like:
<menu title="Second Menu" systemMenu="main" id="usV-GH-tFG" userLabel="New Main Menu">
Now, your app should use the new Main Menu as System Menu. Some submenus should also have systemMenu attributes with the values apple, services, recentDocuments, font or window. If you have made this change, the display in the Interface Builder also changes.
Building a new menu takes a little effort because you have to create quite a few submenus and entries.
But this way you can easily make mistakes, so you should better create a new Main Menu by copying an existing one.
I have an app which is run from the menu bar only (LSUIElement is set in the info.plist) which means there is no main menu except the menu I attached to the status item. The problem is I would like to enable some edit commands when using an NSTextView (like command-c to copy) but all command keys seem to be disabled since the app is technically not active (I get beeps when trying any key combinations).
Is there anyway to add a standard edit menu somewhere and enable command keys that would redirect to it? I'm thinking there could be a hack to make the app temporarily active or something but I can't figure anything out.
Thanks.
They're not disabled. They're gone, because you deleted them.
You need to put back your Main Menu.
If you use version control, you may be able to resurrect it from the past using that. If not, you'll have to create a new project, copy anything custom from your Main Menu nib (if you even still have one) into that one, and move that nib into your actual project to be your new Main Menu nib.
The Edit menu commands, window-related commands (e.g., Close), and numerous other commands all live in the Main Menu. If you delete the Main Menu, you don't have those features anymore.
Your Main Menu isn't visible in a UI element app, but that's not a reason to delete it—it's a reason to keep it, even though your app won't have the menu bar, because not being visible means that it won't peek out from behind the curtain but will remain there keeping the magic of your keyboard shortcuts working.
I have my MainMenu.xib with the Main Menu in it. I also have several NSObject subclasses as Menu Controllers, which are all represented in IB as objects, so that each Menu Item in the Main Menu corresponds to a dedicated Menu Controller
Whenever I try to drag'n'drop some menu item to its Menu Controller header and create an IBAction , Xcode does not give me that option. I suppose it's an Xcode bug, but I'm still confused...
When I created my first Menu Controller everything worked fine. However, now that I've added all Menu Controllers (the very same way as before), only the first one can be "linked" via IB.
What am I doing wrong? Any ideas on how to fix that?
Strange, Make sure the following
you have used the word "IBOutlet" for each to be linkable
clean the code
restart xcode
And just to make it clear,if you think its a bug in your XCode copy, try creating a sample project and see if it also do the strange behavior