I've got two menus in my app, one will be attached to NSStatusBar and another will be app's main menu.
Is there a way to set one of the NSMenu's as the main one right from the Nib? I'm looking at another project's nib and I see the menu actually defined in the nib, while in my nib it's not showing up correctly.
Right now my app has no menu at all.
This is what my nib looks like:
How I want it to look like:
In xibs, at least in Xcode 4, the main menu is no longer an outlet of the application but rather a nature that a top-level menu object either has or doesn't have. The main menu in a main menu nib created by Xcode has that nature; a menu you create yourself does not.
As of Xcode 4.2.1, there is no way to create a menu from scratch in an existing nib and appoint it as the main menu. You must create a nib with the main menu already in it using the appropriate file template.
Related
I create a cocoa application on OSX 10.8. I create a windows derived from NSWindowController and also create a .xib file for this window, I want to show this window when application start, so I add the following in the applicationDidFinishLaunching function
wndAgreement = [[AgreementWindow alloc] initWithWindowNibName:#"AgreementWindow"];
[wndAgreement showWindow:self];
But I still see the application's main window showing. Basically, the main window is behind my window. How to make the main window not show at all and only showing my window? The reason I am doing this is because I am building a wizard application, so click next on one window will open another window and close the current window.
The main window is probably showing because it's in the main menu NIB and has Visible At Launch enabled. "Visible At Launch" really means "visible when the NIB is loaded".
The quickest fix is to turn off Visible At Launch for that window. Better would be to remove that window from that NIB. Although it's the default behavior you get from Apple's project templates, it's a bad idea of have a window in your main menu NIB. They should all be done like your new window, with a separate NIB.
Go to the "Supporting Files" Folder of your project and click on the file that ends in "info.plist." Under "Main nib file base name," you will likely see "MainMenu." Delete this and enter the name of the window you want to show at launch.
In Xcode I've created a new Main Menu xib from the Main Menu template. It only contains the main-menu, which I would like to use in my app.
How can I load this Main Menu from this xib-file and use it in my different windows?
You don't need to do anything.
An application's main menu is already global—it's part of the application, not of any individual window. The same menus will appear regardless of which window is active, by default.
You would have to put in some work if you wanted to go the other way and have different menus depending on which window is active.
How can I display an NSPopover above my app's dock icon?
There are two ways to customise the dock menu, based on if your application is running or not. See the Apple documentation for customising it when its open here:
http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/customizing_docktile/docktasks_cocoa/docktasks_cocoa.html#//apple_ref/doc/uid/TP30000986-CH3-SW1
To summarise, you basically provide a menu in the main application's XIB or storyboard which contains the extra menu options that you want to add to the dock menu.
To customise your Dock icon's menu when the application is not running, see the guide here:
http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/customizing_docktile/CreatingaDockTilePlug-in/CreatingaDockTilePlug-in.html
Basically, you need to create a plugin which you drop into your application's resource folder. This works very like the original method, but executes inside Finder's dock process.
I accidentally deleted the Main Menu menu from IB and now I have a hard time to reconstruct it. I am using Xcode 4.0. Is there anyway to recreate that?
You mean main menu from the menu bar for a mac software ?
If yes, you can simply drag'n drop an NSMenuItem from the IB inspector to your menu bar.
PS : I'm not sure to have understood your question ...
I just can't find the "Create iPad version" button in Xcode 4 because I want to turn an iPhone XIB in an iPad XIB, does anybody know where I can find this button in Xcode4?
This is somewhat hidden. You'll need to create a duplicate target. Select the project in the navigator, then right-click the target and select Duplicate. Choose to Duplicate and Transition to iPad. A group called "Resources-iPad" will be added to your project and will contain the iPad-converted xibs.
You can also do a search-and-replace on a copy of your iPhone .xib file in a text editor, replacing the term "IBCocoaTouchFramework" with "IBIPadFramework".
In addition to Joshua's step you need to set the target to iPhone or it doesn't give you the option to "Choose to Duplicate and Transition to iPad". If the target is set to universal it does not work.
A slightly longer way, to build one from scratch. When all else fails, try the following:
You have to create, through Xcode4, a new MainWindow file for the iPad version.
In Xcode 4, File > New File.
Choose IOS > User Interface > Application, then Next.
Choose Device Family (assume iPad).
Call it MainWindow-iPad.
This creates a new MainWindow-iPad.xib file.
Now, you have to link it to the app delegate.
Click on the new MainWindow-iPad.xib file under your file tab.
Click on App Delegate.
In the inspector window, choose the 3rd pushpin. This is the identity inspector.
Choose the class of your appDelegate.
Now, link it to the window for the screen, plus add any navigation controllers, etc., for this screen.
Go back to the app delegate row under objects, and control-click from the app delegate to the Window, to make that an outlet.
Drag Tab bar controller from the library, and add it below the window.
Control-click on the app delegate, dragging to the tab bar controller. Make that an outlet.
This gives you a complete MainWindow-iPad file.
Now, select the Target, change deployment to Universal, and change the Main Interface under iPad Deployment Info to MainWindow-iPad.
That should do it!