Re: Subclassing NSSearchFieldCell
Re: Subclassing NSSearchFieldCell
- Subject: Re: Subclassing NSSearchFieldCell
- From: Stefan Fisk <email@hidden>
- Date: Wed, 2 Nov 2005 19:02:33 +0100
Is it legal to call the super class's +initialize? Anyways, I've
tried +setCellClass: both from AnimatedSearchField's +initialize, and
from the window controllers, and on both AnimatedSearchField and
NSSearchField. AnimatedSearchField's +allocWithZone: is being called,
as is +cellClass, so why on earth it insists on using
NSSearchFieldCell is above and beyond my comprehension.
2 nov 2005 kl. 18.54 skrev Hamish Allan:
On Wed, 2 Nov 2005 at 16:14:38, Stefan Fisk <email@hidden> wrote:
I've created a subclass of NSSearchFieldCell,
AnimatedSearchFieldCell, that adds support for animating the search
button. Accompanying it I've made a NSSearchField subclass called,
you guessed it, AnimatedSearchField. AnimatedSearchField only
implements +cellClass, and return [AnimatedSearchFieldCell class].
It all works fine when i initialize an AnimatedSearchField from code,
but when i put one in a nib by changing a NSSearchField's class it
doesn't create a AnimatedSearchFieldCell, but instead a
NSSearchFieldCell. +[AnimatedSearchField cellClass] is being called
several times while the nib loads.
I browsed the docs for an hour now, but from what i can gather
overriding +cellClass should be enough.
The docs for NSControl say:
--------
+ (void)setCellClass:(Class)class
Sets the class of cells used by instances of the receiver. If you
have a custom cell subclass that you would like to substitute for
the class of a cell object in a nib file, you should set the cell
class in awakeFromNib (NSNibAwaking protocol). You cannot change
the class programmatically after the cell object has been
unarchived from the nib and instantiated, which occurs immediately
after awakeFromNib returns. If you are going to be using your
custom cell frequently, consider creating you own Interface Builder
palette containing the cell.
--------
This must be why you see different behaviour when you do this from
code and from the Nib.
I've only ever changed the behaviour of an NSSearchField to the
extent of changing the image and the target/action of the
cancelButtonCell, and I had problems finding the designated
initializer. This didn't matter for me as I could do "lazy
initialization" later on, but it sounds as though changing the cell
class is more problematic. Have you tried the following?
@implementation AnimatedSearchField
+ (void)initialize
{
[super initialize];
[self setCellClass:[AnimatedSearchFieldCell class]];
}
@end
Good luck,
Hamish
_______________________________________________
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