NStoolbarItem, custom view, setAction:
NStoolbarItem, custom view, setAction:
- Subject: NStoolbarItem, custom view, setAction:
- From: Tony Romano <email@hidden>
- Date: Mon, 9 Aug 2010 17:37:46 -0700
I'm trying to add a toolbar item that has a custom view. I suspect there is a bug with the NSToolbarItem setAction: method if I choose to use a basic custom view(derived from NSView). In my mouse down, calling [NSApp sendAction:[_toolbarItem1 action] to:[_toolbarItem1 target] from:_toolbarItem1] has no effect, the action selector is nil; The item draws fine, so the view appears to be wired up correctly. (_toolbarItem1 is the correct pointer, fyi).
Overview:
Scenario 1 -If I set the NSToolbarItem's view to a custom view that is derived from an NSControll(most of the ones from the Input and Values controls), then calling set action/target works and in my mouseDown, the action selector is valid and the action gets invoked.
Scenario 2 -If I set the NSToolbarItem's view to a custom view that is derived from NSView(from the layout view such as the basic Custom View), then calling set action/target has NO effect, i.e. the action selector in nil.
According to the documentation, I can use ANY custom view that is derived from NSView.
"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)."
Looking at the documentation for NSToolbarItem setAction:, it has a little note: "For a custom view item, this method calls setAction: on the view if it responds.". Which I infer to mean, that the basic Custom View should work. What really interesting is NSToolbarItem is derived from NSObject(which is a whole other discussion on this design), so the setAction and setTarget need to get stored somewhere, there are no apparent private variables to store these items. Looking at the toolbar item in the debugger, the object knows that the view doesn't support set/get action because they set some bits on creation and look at the bit setting instead of calling respondsToSelector every time.
Anyone have any ideas as to why I can't use a custom view derived from NSView?
Thanks,
-Tony
_______________________________________________
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