• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Custom cell in NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom cell in NSTableView


  • Subject: Re: Custom cell in NSTableView
  • From: James Bucanek <email@hidden>
  • Date: Wed, 1 Jun 2005 08:44:02 -0700

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

  • Follow-Ups:
    • Re: Custom cell in NSTableView
      • From: Gregory Olds <email@hidden>
  • Prev by Date: Searching text
  • Next by Date: Re: CoreData: Inverse relationships not maintained (to-one on one size, to-many on the other, with abstract classes)
  • Previous by thread: Re: Searching text
  • Next by thread: Re: Custom cell in NSTableView
  • Index(es):
    • Date
    • Thread