Re: Custom cell in NSTableView
Re: Custom cell in NSTableView
- Subject: Re: Custom cell in NSTableView
- From: Ryan Stevens <email@hidden>
- Date: Thu, 2 Jun 2005 09:11:13 -0700
I'd stick with the default cell and make the user format the input
(where's the newline?) and draw the separator line from the table
delegate. I'm just cheap like that. :-)
On Jun 1, 2005, at 4:39 PM, Gregory Olds wrote:
This was suggested to me before. That sounds like it would work if
I were trying to just display strings. The problem is that I need
to allow the user to change the values of both text boxes in each
cell.
It looks like the NSView route is the proper one for me. It was
also suggested that I try putting two Text field cells in and use
quartz to draw my thin line between. I will look into this also.
Thanks for your insight.
-Greg
On Jun 1, 2005, at 11:44 AM, James Bucanek wrote:
Gregory Olds wrote on Tuesday, May 31, 2005:
Ok, that makes sense but I'm not sure how to properly subclass
NSCell. What I want to do is put 2 text fields in a sell (one on top
of the other) separated by a thin black line. So do I make a custom
view that looks like what I want and then have the custom cell draw
this custom view inside itself? This would seem to lose the
lightweight advantage of the NSCell.
I know of two ways of doing this.
One is create an NSCell that uses an NSView. As you said, this
(somewhat) destroys the lightweight nature of the NSCell, but not
much. Remember that the key to NSCell's minimal impact on memory
and CPU is the fact the column only creates/uses one NSCell
instance as a "rubber stamp" to draw all of the cells in the
column. I'd start here: <http://www.stepwise.com/Articles/
Technical/2003-12-20.01.html>
The "proper" way to use NSCell is to subclass it and start writing
your drawing code. Rather than using abstract objects like text
fields and such to do your work, your subclass does what NSCells
do -- sets the graphics context and start drawing primatives
(strings, lines, patterns) into the cell.
There are several examples of this in the code distributed with
Xcode. For my latest application, I started with /Developer/
Example/AppKit/SimpleBrowser/FSBrowserCell. This example cheats a
little, because it uses the superclass (NSBrowserCell) to draw the
text and handle some of the background/border/hightlighting
issues. But it does show how to subclass NSCell, override
drawInteriorWithFrame:inView:, set up the graphics context, do the
required background/border drawing, and then draw (in this case,
an NSImage) into the cell. It could be easily reworked to draw
two strings and a line.
--
James Bucanek <mailto: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