Checking facts on NSCell (e.g. in NSTableView)
Checking facts on NSCell (e.g. in NSTableView)
- Subject: Checking facts on NSCell (e.g. in NSTableView)
- From: Luke Evans <email@hidden>
- Date: Thu, 8 Jan 2009 00:31:06 -0800
To date I've taken cells for granted when working with NSTableViews
and the like. I've just set up the appropriate bindings to text or
image data and lo the standard NSCell subclasses do their thing.
Now however I have reason to want to do something 'funkier' in a table
cell: I want to draw a cell using a number of properties from a data
object that is bound.
I see that I can certainly create my own subclass of NSCell, and some
drawing experiments are looking good. However, on looking at how I'd
get at a bound object (to access its properties in the cell drawing
routine to affect the right representation) I'm beginning to think
this is where things get more complicated. The docs seem to suggest
that cells can only be instantiated with an image or text data object
- nothing more complex. The impression I'm getting is that you can
henceforth use these limited values (e.g. most often the text) to
determine an object (an example given is an NSColor) and cache such an
arbitrary object with setRepresentedObject, but it doesn't look like
you can just set the bindings up to produce some arbitrary object type
at the cell and then have the subclass make sense of it directly.
Am I wrong about this interpretation of what I'm reading?
I certainly _could_ provide some kind of stringified reference to an
object that I really want to reacquire in my NSCell subclass, and have
this be the text that gets presented to the cell in its value binding
in order to do a lookup of this unique text to recover the object I
care about. However, this is extremely ugly and will perform badly,
to say nothing of the extra code required. It's hard to believe that
NSCell is intrinsically limited to being created for representing text
or images only (or things easily mangled into these types), and this
makes me feel that I'm missing some subtlety somewhere.
By way of further example, if you had a data model containing some
objects that have, say, an NSColor property, and you want to paint a
simple colour swatch in a custom cell, is there no simple way of
binding the NSColor value to the cell and picking this up in the
cell? Perhaps one has to resort to subclassing the control somehow to
get richer forms of cell instantiation if this is needed???
Cheers
Luke
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden