Using a custom NSCell for NSButton created in IB
Using a custom NSCell for NSButton created in IB
- Subject: Using a custom NSCell for NSButton created in IB
- From: "Stephen F. Booth" <email@hidden>
- Date: Sun, 5 Mar 2006 08:01:02 -0800
I recently ran across an annoying problem that I was able to get
around but it seems there should be a better way, so I wanted to ask
here.
I needed to create a subclass of NSButton/NSButtonCell that would act
as a 'pseudo' mixed-mode checkbox- a button where the user can only
select on or off states, but by selecting multiple items elsewhere
the user might cause the checkbox to indicate a mixed state. This is
easily realized by overriding the -(int)getNextState method in
NSButtonCell and telling NSButton to use the new subclass.
My aggravation came in trying to get NSButton to use the custom
NSButtonCell- I could find no way to create a button in IB and have
it use my custom cell class. I ran across a note in the
documentation about calling setCellClass in awakeFromNib; I created a
custom subclass of NSButton and did just that. However, the NSButton
continued to use NSButtonCell instead of my custom subclass,
presumably because the NSButton instantiated in IB was using
NSButtonCell instead of the custom class.
All the custom control examples use custom IB palettes, which
obviously use custom NSCell subclasses; I toyed with the idea of
writing an IB palette but it seemed like a waste of time for such a
simple requirement.
I finally got around the problem by creating a custom view in IB
assigned to a custom NSButton subclass that is configured
programmatically the way I want in awakeFromNib. This approach is
far from ideal because there is no way to modify/preview/alter any of
the numerous NSButton attributes using IB.
Is there an easier way I just missed?
Thanks,
Stephen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden