On May 11, 2009, at 6:03 PM, Gunnar Proppe wrote:


Howdy Jon,

Thanks for the tips, I'll give that a try. The first suggestion sounds close to where I was going to go, except I hadn't thought of instantiating the view in the NIB file. Great idea.

Your alternative suggestion sounds interesting but I'm not sure I understand it. Would I then set the class name in the Identity pane of this pasted, plain NSView to my custom class?

Yes.

What's different about this plain NSView from the "custom view" dragged from the library?

The "Custom View" has additional behavior beyond an NSView. One way they are different is that when a custom view is instantiated from a NIB file it receives the initWithFrame: message instead of initWithCoder:.


Is this a bug in Interface Builder, or did I misread the linked documentation?

This is a bug in Interface Builder.

Jon Hess


From the doc:

"The procedure for adding a custom view item is very similar to that for a custom image item. (“Custom” in this context means any object from the Interface Builder library as well as instances of a custom NSView subclass.) Just drag any view object from the library onto the Allowed Toolbar Items area. Click the item once and press Command-1 to display the Attributes pane for the object as a toolbar item; click again to edit the attributes of the item as itself. You should modify the size of the custom view item in the Size pane of the inspector, not directly. If you drag a Custom View object into the allowed-items set, click it twice and set the name of the custom NSView class in the Identity pane of the inspector (Command-6)."

Gunnar


----- Original Message ----
From: Jonathan Hess <jh...@apple.com>
To: Gunnar Proppe <toneclus...@yahoo.com>
Cc: cocoa-dev@lists.apple.com
Sent: Monday, May 11, 2009 4:35:49 PM
Subject: Re: NSToolbarItem with custom view in Interface Builder 3 (Leopard)

Hey Gunnar -

You won't be able to make this work with an instance of "custom view" dragged
from the library. Here are a couple of suggestions for workarounds:

You could add an outlet to the toolbar item you'd like to use a custom view with, and then place the custom view at the top level of your NIB, and also add an outlet to it. In awakeFromNib, you could call setView: on the toolbar item
with the correct view.

Alternatively, you could use a view object that wasn't a custom view. Interface Builder doesn't provide a view object in the library that isn't a specific subclass or NSView, or a custom view, but you can get a hold of a plain NSView by copying and pasting one from someplace else. For example, copying a window's content view by using Interface Builder's outline view will get you a vanilla instance of NSView. Paste one into the top level of a document and resize it to a reasonable size, and and then you can drag it from the document window into
the toolbar.

Good Luck -
Jon Hess

On May 9, 2009, at 11:36 AM, Gunnar Proppe wrote:


I followed the steps described here to set up a toolbar item with a custom
view in Interface Builder:

http://developer.apple.com/documentation/Cocoa/Conceptual/Toolbars/Articles/ToolbarInIB.html

Unfortunately my custom view's drawRect is never called. I verified that it
does get initialized. The toolbar item's min and max size are set up properly. Just to be safe I had my view conform to NSCoding but initWithCoder and ecodeWithCoder aren't called. I tried various springs and struts settings with
no results.

Digging deeper, I subclassed NSToolbarItem and overrode setView and setMinSize
so I could break on them. setMinSize is getting called with the correct values. Interestingly, setView gets called before my custom view is initialized. I assume this is the proxy NSView object. Then my custom view is initialized (initWithFrame) but the NSToolbarItem's setView isn't called again with the new view instance. I don't know if this is a bug -- maybe Cocoa does some voodoo in
the swapping from the proxy NSView object to the custom view.

Standard views work fine: eg. NSButton and NSBox.

Has anyone successfully used IB to create toolbar items with custom views?

Thanks,
Gunnar



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jhess%40apple.com

This email sent to jh...@apple.com





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to