On Sep 6, 2009, at 08:41, Gregory Holden wrote:

NSArrayController seems great if you want to point it at repeating objects, but I can't find any clear way to add that one-off column that isn't part of the actual model objects (i.e. The "Now Playing" speaker in itunes, or a column with row numbers - independent of sorting).

If you want to use a binding, then the data model** must have a property to bind to. You have 3 choices for that:

1. A derived property (a property whose value is produced on the fly, which isn't backed by its own instance variable in your data model).

2. A transient property (a property backed by its own instance variable which isn't saved when the data model is saved, and which is reinitialized when the data model is loaded).

3. A persistent property (i.e. a normal property).

#3 may seem like an odd choice, but if calculating the property value is expensive or awkward, it may be cheaper overall just to "waste" the disk space involved in making the property persistent.

I did try setting up the bindings AND a datasource on the same table. It appears to work, but it also seems very dangerous as I'm obviously still getting requests for the bound data via tableView:objectValueForTableColumn.

It may feel "dangerous" but for me it's always worked just fine to bind some columns and to use a data source for others. I've never seen any documentation saying that the technique is unsupported. So go for it, I'd say.


**I should have said "a data model" instead of "the data model". Depending on what the property represents, you may choose to add it to (say) the window controller instead of your actual data model. If you follow that approach, then you'll likely also need to have the window controller observe the underlying data in the data model. That's more work, but consider the case you where might want to have row numbers in table views of the same data in 2 different windows, where the tables might be sorted differently. Obviously in that case you can't supply the row numbers from the underlying data model.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to