I've already killed a day on this subject and still got no idea on how could this be done in a correct way.
I'm using NSOutlineView
to display filesystem hierarchy. For each row in the first column I need to display checkbox, associated icon and name of the file or directory. Since there's no standard way to make this, I've subclassed NSTextFieldCell
using both SourceView and PhotoSearch examples, binding value
in IB to name
property of my tree item class though NSTreeController
. I'm using drawWithFrame:inView:
override to paint checkbox and image, forwarding text drawing to super
. I'm also using trackMouse:inRect:ofView:untilMouseUp:
override to handle checkbox interaction.
Everything was fine up until I noticed that once I press mouse button down inside my custom cell, cell object is being copied with copyWithZone:
and this temporary object is then being sent a trackMouse:inRect:ofView:untilMouseUp:
message, making it impossible to modify check state of the original cell residing in the view.
Since the question subject is about binding, I thought this might be the answer, but I totally don't get how should I connect all this mess to function as expected. Tried this:
[[[treeView outlineTableColumn] dataCell] bind:@"state"
toObject:treeController
withKeyPath:@"selection.state"
options:nil];
but didn't succeed at all. Seems like I'm not getting it.
May this be a completely wrong way I've taken? Could you suggest a better alternative or any links for further reading?
UPD 1/21/11: I've also tried this:
[[[treeView outlineTableColumn] dataCell] bind:@"state"
toObject:treeController
withKeyPath:@"arrangedObjects.state"
options:nil];
but kept getting errors like "[<_NSControllerTreeProxy 0x...> valueForUndefinedKey:]: this class is not key value coding-compliant for the key state." and similar.