views:

78

answers:

1

I have a NSOutlineView and I want to make the text for a row change color when the rows check box has been checked.

The Outline View looks like:

 _     _________________
|_|   |____TEXT CELL____|
 _     _________________
|_|   |____TEXT CELL____|
 _     _________________
|_|   |____TEXT CELL____|
(CHECKBOX)

How would I do this.

+2  A: 

If you can target 10.6, implement tableView:willDisplayCell:forTableColumn:row: in your table view's delegate to set the cell's text color based on the value of whatever property that backs the checkbox.

Peter Hosey
Hmm. Isn't there an easier way, I seem to remember something about using a Binding to do this, is that possible?
Joshua
It's possible to bind the table column's text color, yes. But your question sounds more like you're using text color to display the same property as the checkbox in a different way, which means that the text-color binding—which would require a text-color property of the model object—isn't appropriate.
Peter Hosey
So would the code look a bit like this, http://fwdr.org/z2ek. But what would I put where I said 'What would I put here' to check if the check box on the row is checked?
Joshua
First, you need to make sure you're looking at the correct column, which you can do by comparing the column's identifier (you *did* assign the columns identifiers in IB, right?). This is better than a `respondsToSelector:` check, since you may have multiple text cells.
Peter Hosey
Next, get the model object at the specified row, then get its value for the property that the checkbox column shows. Set the cell's `textColor` based on that value.
Peter Hosey
Is this better. http://pastebin.com/d225a6b33. Does the Code at the top get the model object at the specified row? However, I still don't understand how I would 'get its value for the property that the checkbox column shows'.
Joshua
Well, you wrote it. You tell me what it does.
Peter Hosey
Item equals the item at row index.
Joshua
That's just reading it literally. What does it *do*?
Peter Hosey
It is the Row that is Selected or at the row index.
Joshua
I don't see a condition in that statement. That means it only does one thing, not one thing or a different thing. So: Which one is it?
Peter Hosey
Ok, So it does one thing.
Joshua
I already said that. Which one?
Peter Hosey
Ok. It's the row at the row index.
Joshua