Subclassing NSTextFieldCell
Subclassing NSTextFieldCell
- Subject: Subclassing NSTextFieldCell
- From: Christopher Corbell <email@hidden>
- Date: Thu, 1 May 2003 12:17:25 -0700
Hi,
I'm having trouble getting a subclass of NSTextFieldCell to work
as expected.
My goal here is to implement a rounded search edit control similar to
that in the finder, Mail.app, etc. I expected the shortest path would
be
to leverage the existing NSTextField with its rounded appearance, and
just
override drawing, some mouse handling (at the ends) and text-rect
calculation.
The attempt is breaking down at a few places, related to cell
subclassing.
I've subclassed NSTextField as well as NSTextFieldCell - call 'em
MyTextField and MyTextFieldCell. In MyTextField +initialize, I
call [MyTextField setCellClass:MyTextFieldCell]. However if I then
load a nib that has a MyTextField object, it does not appear to
actually create a MyTextFieldCell object - it just creates a standard
NSTextFieldCell. Is this a limitation of nibs - that one can't
loading a control from a nib ignores any custom-set cell class?
I have verified that, at the time the nib is loaded, MyTextField's
cellClass
method returns MyTextFieldCell. However the actual cell object
created during nib loading is a standard NSTextFieldCell. If I
leave things as-is it looks and behaves like the standard control.
As a workaround in the field's awakeFromNib I explicity allocate a
MyTextFieldCell object with alloc and initTextCell, and call setCell.
This does result in the control getting a MyTextFieldCell. Here the
other unexpected behavior comes in. Even if MyTextFieldCell is
a completely empty subclass - all methods are inherited NSTextFieldCell
methods, no overrides - the standard drawing and behavior is lost.
If I override drawWithFrame I can draw custom things, but calling
[super drawWithFrame] from this method does not cause the
standard NSTextFieldCell drawing to happen, nor does standard
editing or mouse-handling work.
Am I misunderstanding the whole NSControl-NSCell mechanism,
or are there idiosyncrasies with NSTextField/NSTextFieldCell that aren't
documented? Or am I seeing actual bugs?
Thanks for any help,
Christopher
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.