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: email@hidden
- Date: Sun, 5 Mar 2006 16:30:48 -0500 (EST)
- Importance: Normal
I actually tried this before, and it does not work. My NSButton subclass
for some reason still uses NSButtonCell instead of my custom cell class.
(When I print out the type of [self cell], it is NSButtonCell.) I see
that +cellClass is being called, but my custom cell class' getNextValue is
never called.
This was exactly the root of my frustration; it seems that overriding
+cellClass should do the trick and it doesn't. Even the docs allude to
this. As I mentioned, I have a feeling it is because the button object is
being instantiated using initWithCoder, which sets up the object using the
archived NSButtonCell instance instead of creating a new one of the
specified type.
Stephen
> 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