Re: NSToolbarItem with custom view in Interface Builder 3 (Leopard)
Re: NSToolbarItem with custom view in Interface Builder 3 (Leopard)
- Subject: Re: NSToolbarItem with custom view in Interface Builder 3 (Leopard)
- From: Jonathan Hess <email@hidden>
- Date: Mon, 11 May 2009 16:35:49 -0700
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 (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden