FROM : Ricky Sharp
DATE : Fri Dec 10 20:08:40 2004
On Dec 10, 2004, at 8:54 AM, Ricky Sharp wrote:
> I need to head out for a bit, but will follow up on this thread with
> the minimal implementation one needs to do when deriving directly from
> NSCell.
If you have a subclass of NSCell, you need to provide an implementation
for setTag: as NSCell will raise an exception in its implementation.
At the minimum, I've found that you should:
(1) Add the following iVar to your cell subclass:
int tag;
(2) Add -tag and -setTag: accessors.
(3) In your cell's designated initializer, initialize tag to something
(e.g. 0). I use my accessor to do this.
(4) In your encodeWithCoder and initWithCoder methods, encode/decode
this iVar.
(5) In your copyWithZone, make sure to copy this tag attribute.
(6) There's nothing you need to do to your NSControl subclass; it
already has default implementations of tag and setTag: that simply call
through to the cell's implementation.
(7) If you want to allow editing the value of the tag in IB, of course
add an appropriate control to your inspector.
Now then, it will take more work to have a system that will
automatically assign unique values to your tag when you drag out an
NSMatrix of such cells. But, at least you'll have the code in place
that will allow alt-dragging to work.
BTW, the main reason I overlooked this whole 'tag' thing was that none
of the docs on subclassing NSCell brought it up. I'll be filing a
documentation enhancement request later on to point out some of these
gotchas.
___________________________________________________________
Ricky A. Sharp mailto:<email_removed>
Instant Interactive(tm) http://www.instantinteractive.com
DATE : Fri Dec 10 20:08:40 2004
On Dec 10, 2004, at 8:54 AM, Ricky Sharp wrote:
> I need to head out for a bit, but will follow up on this thread with
> the minimal implementation one needs to do when deriving directly from
> NSCell.
If you have a subclass of NSCell, you need to provide an implementation
for setTag: as NSCell will raise an exception in its implementation.
At the minimum, I've found that you should:
(1) Add the following iVar to your cell subclass:
int tag;
(2) Add -tag and -setTag: accessors.
(3) In your cell's designated initializer, initialize tag to something
(e.g. 0). I use my accessor to do this.
(4) In your encodeWithCoder and initWithCoder methods, encode/decode
this iVar.
(5) In your copyWithZone, make sure to copy this tag attribute.
(6) There's nothing you need to do to your NSControl subclass; it
already has default implementations of tag and setTag: that simply call
through to the cell's implementation.
(7) If you want to allow editing the value of the tag in IB, of course
add an appropriate control to your inspector.
Now then, it will take more work to have a system that will
automatically assign unique values to your tag when you drag out an
NSMatrix of such cells. But, at least you'll have the code in place
that will allow alt-dragging to work.
BTW, the main reason I overlooked this whole 'tag' thing was that none
of the docs on subclassing NSCell brought it up. I'll be filing a
documentation enhancement request later on to point out some of these
gotchas.
___________________________________________________________
Ricky A. Sharp mailto:<email_removed>
Instant Interactive(tm) http://www.instantinteractive.com
| Related mails | Author | Date |
|---|---|---|
| Ricky Sharp | Dec 10, 20:08 | |
| Ricky Sharp | Dec 10, 23:01 |






Cocoa mail archive

