Conditional column values in NSTableView?

Posted by velocityb0y on Stack Overflow See other posts from Stack Overflow or by velocityb0y
Published on 2010-05-19T05:02:23Z Indexed on 2010/06/01 1:23 UTC
Read the original article Hit count: 277

I have an NSTableView that binds via an NSArrayController to an NSMutableArray. What's in the array are derived classes; the first few columns of the table are bound to properties that exist on the base class. That all works fine.

Where I'm running into problem is a column that should only be populated if the row maps to one specific subclass. The property that column is meant to display only exists in that subclass, since it makes no sense in terms of the base class. The user will know, from the first two columns, why the third column's cell is populated/editable or not.

The binding on the third column's value is on arrangedObjects, with a model path of something like "foo.name" where foo is the property on the subclass. However, this doesn't work, as the other subclasses in the hierarchy are not key-value compliant for foo.

It seems like my only choice is to have foo be a property on the base class so everybody responds to it, but this clutters up the interfaces of the model objects.

Has anyone come up with a clean design for this situation? It can't be uncommon (I'm a relative newcomer to Cocoa and I'm just learning the ins and outs of bindings.)

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about nstableview