On 10 Dec 2008, at 12:21 pm, Randall Meadows wrote:

I could use a little guidance, please, on customizing cells for display in an NSTableView. (My app is Leopard-only.) I looked around the Apple docs and cocoadev, but didn't really find anything useful. Other pointers would be appreciated.

My table has but one column, but each cell in that column is made up of 2 or more views. I think I have what I need as far as the cells go, but it's feeding them to the table view that's giving me problems.


The first thing to realise is that there is not one cell per row. There is only one cell per column. The single cell is "moved" from row to row as the table draws the rows. Once you realise that there is only one cell, things become a bit clearer.

I'm not sure what you mean by each cell having two views. Do you literally mean NSViews, or are you using the term more loosely? AFAIK, it's really not feasible to embed actual NSViews in a cell.

I know the "required" datasource methods are - numberOfRowsInTableView: and - tableView:objectValueForTableColumn:row:; the first is a no-brainer, the 2nd one stumps me.

The second one gets the actual value for the row/column in question. Without this your table wouldn't draw anything because it doesn't know what to draw - the table is entirely generic and makes no assumptions about what the data content is.

Because there is only one cell per column, this method is used whenever needed to give the data to the cell at the right time.

I assume I must implement -tableView:dataCellForTableColumn:row: to feed the table my custom cells for each row, right?

Not normally. This method is used when you have different cell types for each row, which is fairly uncommon. Typically you set the cell for the entire column in one go. You can do this in IB, or else programatically using [NSTableColumn setDataCell:]

What purpose then does the -tableView:objectValueForTableColumn:row: method serve? What should be returned from that if I'm already feeding ready-made cells from the other one? (This table is not editable, so I do not need to worry about - tableView:setObjectValue....)

Don't feed cells per row unless you have to. Set the cell once for the column, then let the dataSource supply it on demand with its data.

The docs also say that my cells must "properly" implement - copyWithZone:, but I don't know what "properly" means in that context.

I guess it means that your copy method must return a real copy, not just retain and return self, since cells are considered always mutable - the table must be allowed to mutate the cell as needed with no side effects.

hth,

Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to