'Embed Objects In' menu items are all disabled. How to enable? - xcode

I'm following the instructions for creating a ScrollView in the book 'Cocoa Programming for Mac OS X, 3rd Edition'. I'm using Xcode 3.2.3.
I've already created a view, into which I've drawn shapes and lines.
The next task is to convert this to a NSScrollView, which according to the book should be a simple case of selecting the existing view and choosing Layout -> Embed Objects In -> Scroll View.
However whatever object I select, the items in the 'Embed Objects In' menu are all disabled.
How can I enable the Embed Objects In -> Scroll View item?

Got it. The important thing here is not to try selecting the view in the MainMenu.xib window. Select the view in the actual document window and make sure the resize handles are visible. A little fiddly, but once you get the right object selected, then the embed objects menu items become enabled.

Related

How do you set menuFormRepresentation for an NSToolbarItem in IB?

How do you set the menuFormRepresentation for an NSToolbarItem in Interface Builder?
I was trying to transition from programmatically constructed window toolbars to ones created entirely in IB (with an ultimate goal of easier localization).
I'm also transitioning from image-based items to view-based item to support NSButton and NSSegmentedControl items.
My first step was to just modify the existing code to create view-based toolbar items instead of image items. That works just fine.
My next step was to rip out all of the code and use just IB (Xcode 9.2) to create the toolbar and toolbar items. Most of it works, but the NSButton items don't get enabled or disabled properly.
When I wrote the code, I had to create NSMenuItem (or NSMenu) objects for each toolbar item and use that to set the item's menuFormRepresentation property. According to the documentation "Setting a Toolbar Item’s Representation", if you don't do this a view-based item (a) won't get validated automatically and (b) will not appear in the text-only version of the toolbar or the overflow menu.
I've looked everywhere in IB I can think of, but there's no outlet, property, or attribute where you can set the item's menuFormRepresentation property. I've also tried dragging and dropping a menu item on the toolbar item; nothing happens.
The documentation for "Creating a Toolbar in Interface Builder" doesn't make any mention of what to do about menuFormRepresentation, yet without it the item is functionally crippled.
Is this a huge hole in IB or am I missing something?

Different menubar in document based apps

I've a cocoa app based on NSDocument, I've two types of document.
Every document type has its own menu items, all items are defined in mainmenu.xib.
As defined in Apple UI guidelines the menu items irrelevant for a doc type are shown grayed.
I have too much menu items so I want to show only relevant items per doc type, another problem is created by the key bindings, for doc type A a particular key binding is associated to a menu item but for doc type B the same key bindind is associated to another menu item but this isn't possible because XCode detects the same key is already used and it removes (correctly) from previous item definition.
I want to create a menu similar to XCode's 'Editor' menu, it shows some items when focus is on a text window and a totally different item set when focus is on a IB file.
Are there best practices? For example splitting menus.
How can I easily create a menu similar to XCode's 'Editor' menu?
Which API cocoa gives us to do it?
You can create the separate menu(s) in the MainMenu.xib and create outlets to them from the App Controller. Then when your document gains focus (see windowDidBecomeMain (reference)), you tell the App controller to switch-out the relevant parts of the main menu.
Switching-out the parts of the main menu is done by trawling the main menu hierarchy and assigning the separate menu at the right place (i.e. [NSMenuItem setSubmenu:] (reference)). You can make this easier for yourself by setting tags, using Interface Builder, in those menu items and then using [NSMenu itemWithTag:] (reference) to find them programmatically.

NSTextField with automatic NSNumberFormatter in Interface Builder

I've been making iOS apps for awhile, but I'm trying my hand at MacOS development. I'm adding an NSTextField to my UI and I noticed in Xcode that one of the options in the graphical widgets is "NSTextField with NSNumberFormatter" which implies to me that I'll be able to restrict the input of the field to numbers and configure the formatter in some way.
When I add the NSTextField with NSNumberFormatter to my UI, I can see it has a formatter outlet which appears to be kind of linked to an NSNumberFormatter (although the name is a little grayed out). However, I can't figure out any way to interact with or configure that NSNumberFormatter.
Any help?
To access the NSNumberFormatter, you have to select it in the dock (that list of objects on the left side of the XCode 4 Interface Builder [IB] window).
If the dock isn't in outline view, e.g., it just shows about 4 icons, click the triangle-in-a-square-button at the bottom of the dock. The dock should now show a "Placeholders" section and an "Objects" section; the objects are your UI objects in a hierarchical outline view.
In the IB window, click your NSTextField; that'll highlight the corresponding Text Field Cell in the outline (you may have to twiddle down some disclosure triangles to see it). The Text Field Cell should have a disclosure triangle; twiddle it down to reveal the Number Formatter. Select it, and you should now be able to manipulate it in the Inspector panel.
(There are a lot of things non-obvious like that in XCode. When in doubt, examine your UI object in the Dock's outline view, or prowl the menus with that object selected. It's amazing--and often useful--what you can discover lurking there!
to configure the number formatter, you can ( after you've selected the formatter ) open the Attributes inspector, select the behavior you want and customize the formatter. At least that worked for me in XCode 4.
– moritz

How to access an NSNumberFormatter in a text field cell?

In XCode 3.2.x's Interface Builder this was simple enough, selecting the text cell displayed a small icon for the formatter that could be selected to configure the formatter in the attributes pane.
Now in XCode 4, the formatter icon is gone! If I drag an instance of NSTextField with an NSTextFormatter from the library OR drop and NSTextFormatter into an existing cell there is no way I can figure out to select the formatter to configure it!
Add to this the fact that Core Data entities UI prototype assistant was removed and I would say IB integration into XC4 is half baked at best!
Any luck with this anyone?
you can access the formatter from the jump bar at the top of the window. if you select the component you added the formatter to, click and hold and it will turn into a drop down menu. move to the sub menu and the formatter should show up where you can select it.
it seems that you can treat the whole ui like a cascading set of menus that way.
now removing the formatter, that's a different question...
... which after further looking revealed:
over on the left side of the IB window in xcode4 is a 'dock' containing the icons for file owner, first responder etc. this column is expandable, and when you do so will show a hierarchical view of the nib file. through which you can navigate like the finder.
also, see this article:
http://developer.apple.com/library/mac/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/InterfaceBuilder/InterfaceBuilder.html%23//apple_ref/doc/uid/TP40010215-CH6-SW3

What type of View is that slim bar above the editor in Xcode?

I want to use the same sort of UI style of Xcode has right above the editor pane, as show below:
I've browsed through all the Views in Interface Builder and can't figure out what type of view this is. At this point I'm merely referring to the bar itself; not to the controls nested inside the bar, though I will be adding dropdowns in the same way as this.
What type of view should I be looking for?
TextMate uses one along the bottom of the editor too, which provides similar controls:
see:
$(DEVELOPER_ROOT)/Applications/Utilities/Accessibility Tools/Accessibility Inspector.app
just open Accessibility Inspector.app and move the cursor over the views you're interested in for details (you may need to enable accessibility options in system preferences.app).
it's also helpful to press cmd+F7 to lock onto a view and then to inspect its children.
so... 3 primary options:
1) if you want drag & drop convenience, you can simulate it with a Gradient Button
2) or you can use the button with a custom image in the button to achieve something closer
3) or just create a new view subclass and render it using a CGGradient or NSGradient

Resources