NSTextField inside NSOutLineView w/ cocoa bindings

Dear all,


I'm using a NSOutlineView with non-dynamic content to display an Xcode-like inspector view.

I would like to bind one of the NSTextField in my inspector view to one variable in the controller class.


Can I achieve this simply or will the NSOutlineView prevent me to do so?


Cheers,


yellow8

Replies

Assuming this is a view-based outline view, not a NSCell-based view …


You can bind the text field value via the "objectValue" property of the cell view containing the text field. (When you try to establish the binding, the cell view will be one of two choices in the popup menu where you choose what object to bind to.)


Typically, you'll have an implementation of the 'outlineView:viewFor:item' delegate method. In that method, you can set the "objectValue" property of the cell view you're returning to a suitable object for the column/item of the cell.


Note that in a simple case, the "objectValue" could just be a string that's the value of the text field, or it can be a custom object that has the string as a property. In that case, back in IB, you'd specify something like "objectValue.myStringPropertyName", but using the actually string property name.


I hope that makes sense. It's actually pretty straightforward, but hard to describe clearly in words.

If the text field is editable, rather than just a label, you definitely want the cell view's objectValue to be a model object where the string is a property. That's the only way the binding will mutate the model rather than just the cell view.


Also, it's not clear if this is an outline view with static content which was specified directly in the NIB. It's not clear what "with non-dynamic content" means. I've never worked with those and don't know if they take an object value from the data source.