Re: Using a custom NSCell for NSButton created in IB
Re: Using a custom NSCell for NSButton created in IB
- Subject: Re: Using a custom NSCell for NSButton created in IB
- From: Greg Herlihy <email@hidden>
- Date: Sun, 05 Mar 2006 11:18:59 -0800
- Thread-topic: Using a custom NSCell for NSButton created in IB
If you go the Custom View route than IB won't know that the custom view is
actually a button, as you have found out.
A better idea is to replace the custom view with the standard button that
the custom button inherits from. Then with this button selected, go to the
"Custom Class" pane in the Inspector and set the button's class to your
custom class. In this way, IB will treat your custom button as a button
control. And the easiest way to add your custom class to the list that IB
shows when selecting a custom class, is to open the header file of the
custom button class and then drag the document icon in its window's title
bar onto Interface Builder's main window.
And the only routine that the custom button needs to implement is +cellClass
(note it's a class - not an instance method). +cellClass just needs to
return the class of your custom cell type.
Greg
On 3/5/06 8:01 AM, "Stephen F. Booth" <email@hidden> wrote:
> 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
_______________________________________________
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