Re: Updating table rows with bindings
Re: Updating table rows with bindings
- Subject: Re: Updating table rows with bindings
- From: Keary Suska <email@hidden>
- Date: Thu, 31 Jul 2008 09:21:58 -0600
- Thread-topic: Updating table rows with bindings
7/31/08 1:00 AM, also sprach email@hidden:
> When an NSTableView is set up with bindings and NSArrayController,
> what is the right way to modify a row? I see NSArrayController
> methods to add and remove objects, but nothing to modify one. I guess
> I could remove and then add, but that seems ugly.
NSArrayController does not have any concept of "row", or even any idea
whatsoever what kind of objects its content array contains. They don't even
have to be the objects of the same class. That's concept #1. An object's
properties are modified using Key-Value Coding. That's concept #2.
> Before I started with bindings, it wasn't a problem. The model array
> for the table was an NSMutableArrray of NSMutableDictionary, so I
> could just find the dictionary for the row and update it. But
> apparently [[ arrayController arrangedObjects] objectAtIndex: i ]
> returns an immutable dictionary, so I can't do it that way. I can't
> see how to work with the model array directly any more, because any
> way I get indexes of selected items gives indexes into the arranged
> objects, not the original array.
If [[ arrayController arrangedObjects] objectAtIndex: i ] I returning an
immutable object, it's because that is what you are putting into
arrayController 's content array. Use mutable dictionaries instead.
Also, any programmatic changes to models should be done directly to the
model, and not through the controller's content, unless you are using the
controllers specific methods for manipulating content (such as -addObject:).
Lastly, there is no reliable way to map an array controller's
arrangedObjects to the model array, without making dangerous assumptions.
Why would you need this anyway? -selectedObjects will give you all the
objects you care about. (rhetorical question for most--there may be
situations, but IMHO this approach reveals a design flaw 99.99% of the time)
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden