Re: NSTableColumn dataCellForRow:
Re: NSTableColumn dataCellForRow:
- Subject: Re: NSTableColumn dataCellForRow:
- From: Quincey Morris <email@hidden>
- Date: Mon, 21 Mar 2011 21:22:03 -0700
On Mar 21, 2011, at 16:16, William Weygandt wrote:
> I need to set attributes for a TableColumn cell, based on its row, leaving the cells of other rows, unchanged. I tried using the method dataCellForRow:. I just can't seem to make this work. Not sure I can subclass this because the delegate will reference this method.
Can you ask a more specific question. We've no idea what you've tried and what's failed. We don't know what you mean by "can't seem to make this work". You might want to post some failing code, if you're not sure how to describe the problem. Meantime ...
You shouldn't think in terms of subclassing NSTableColumn -- it just makes it too hard to set things up in IB.
Instead you should use one or both of the delegate methods 'tableView:dataCellForTableColumn:row:' and 'tableView:willDisplayCell:forTableColumn:row:' (or the parallel variants used by outline views). All you have to do is the keep them straight in your mind.
'tableView:dataCellForTableColumn:row:' is called to obtain a cell to use at a specific row/column position, in case you want to use a different kind of cell (or for some reason just a different cell) from the default provided by the column. At the time this is called, the cell is not being configured yet, just being obtained, so anything you do to it is subject to being undone by NSTableView.
'tableView:willDisplayCell:forTableColumn:row:' is called sometime after that to configure a cell for use, whether the cell was provided by your 'tableView:dataCellForTableColumn:row:' or not. (The "not" case happens when you don't implement that delegate method, or it returns nil.) When this second method is called, the cell has already been configured as far as the table view knows how (e.g. it's set the correct object value), so you can make any further adjustments you need.
So, if your table column has a text field cell, you would use the first delegate method (for example) to change to an image cell in certain rows. Or, if a text field cell has been chosen for the row/column, you would use the second delegate method (for example) to change the color of the text. Or, if you needed to change to an image cell for some rows *and* configure the image being displayed, you'd do that in two steps, using one delegate method for each.
Does that help at all?
_______________________________________________
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