Updating table rows with bindings

2008-07-31 Thread James W. Walker
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.


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.

___

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 [EMAIL PROTECTED]


Re: Updating table rows with bindings

2008-07-31 Thread Keary Suska
7/31/08 1:00 AM, also sprach [EMAIL PROTECTED]:

 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 (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 [EMAIL PROTECTED]


Re: Updating table rows with bindings

2008-07-31 Thread James W. Walker


On Jul 31, 2008, at 8:21 AM, Keary Suska wrote:

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.


I was mistaken, it is mutable.  I was confused because I had tested with

NSLog(@arranged object class = %@, [rowDict class]);

and got arranged object class = NSCFDictionary.  I thought I would  
see the word mutable there.

___

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 [EMAIL PROTECTED]