Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom cell in NSTableView



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.

Thanks for your reply,

-Greg
On May 31, 2005, at 11:16 AM, James Bucanek wrote:

Gregory Olds II wrote on Monday, May 30, 2005:


Hello all.  I'm new to Cocoa programming and am trying to make a
table view where all but the first column have a cell which contains
2 text fields separated by a think black line.  I'm not sure where to
start to achieve this. Do I subclass NSCell and do some magic there,
or do I just create a kind of custom NSView?  I've looked at many
examples but I can't quite figure out from them where to begin.  Any
help would be appreciated.


An NSTableView consists of a data model (where it gets the values to display), and a collection of NSTableColumn. Each column object has two NSCell objects: One for displaying the value of the column header and one for displaying the value of each cell in the column.


If all of your formatting can be easily done *inside* the boundries of an individual cell, then the easiest thing by far is to subclass NSCell (or some subclass of NSCell) to do the work.

Once you've created your NSCellSubclass, create an instance of it and set that cell object as the "dataCell" for each column by calling -[NSTableViewColumn setDataCell:(yourCustomCellObject)];

Two important things to keep in mind:

- There is only once instance of NSCell per column (unless you override NSTableColumn's dataCellForRow). That single instance is reused, over and over again, to draw the contents of every cell. This avoids the need to allocate an NSCell for every cell in the table. But it does mean that your cell has to be reusable and be efficient about it (i.e. no long, protracted, calculations during - [NSCell setObjectValue]).

- Your custom NSCell gets copied -- a lot. Make sure your custom NSCell conforms to the NSCopying protocol. (This bit me just last week.)

--
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: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Custom cell in NSTableView (From: James Bucanek <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.