Re: Sync problems with NSArrayController + NSSortDescriptor + NSTextField
Re: Sync problems with NSArrayController + NSSortDescriptor + NSTextField
- Subject: Re: Sync problems with NSArrayController + NSSortDescriptor + NSTextField
- From: Quincey Morris <email@hidden>
- Date: Sun, 11 Jan 2009 20:55:35 -0800
On Jan 11, 2009, at 09:54, Dado Colussi wrote:
I have an NSTableView with a single column bound to an
NSArrayController that manages an entity in an XML Core Data
storage. I have programmatically added one NSSortDescriptor to the
array controller for attribute 'name'. I have bound the table's
'content' and 'selectionIndexes' to the array controller, and left
the 'sortDescriptors' unbound. From mmalc's controller examples I
understand that this prevents the user from manipulating the sort
descriptors when interacting with the table.
In my detail view, I have an NSTextField that is has its 'value'
bound to the array controller's 'selection.name'. I also have other
text fields bound to other attributes in the array controller,
essentially to attributes that are not part of the sort descriptor.
When I modify the text field for attribute 'name' and press enter,
the value in the table view changes, and the item gets sorted
properly. However, the text field reverts to the previous value, as
if I had not changed it, and I lose focus on the text field.
Changing selection in the table refreshes the text field back to
sanity. For the sake of curiosity, I added another NSTextField and
bound it to the same attribute 'name'. I discovered that the problem
occurs only with the text field that is edited. The non-edited text
field is updated correctly. I also tried removing the table
entirely, and it did not help.
1. If you change the text field for attribute 'name' to a different
value but one that doesn't change the order of the rows, does it work
correctly? (Prediction: Yes)
2. It sounds like the table is losing track of which row the field
editor (the singleton text field that actually handles editing) is
attached to when you change the order of the rows "during" editing.
Normally, when you press Enter, the table view has to update the row
that was underneath the field editor, but if it updates the wrong row,
then the old value will show until something else updates it (like
changing the selection).
It sounds like, under Tiger, the table view or the array controller
isn't trying to observe changes to the sort descriptor, so nothing
happens when you end editing -- neither the re-sort or the problem you
saw.
It sounds like, under Leopard, the sort descriptor *is* being
observed, and the KVO notification is arriving before the table view
expects it. Or something like that.
It also sounds like a good candidate for a bug report.
One possible workaround might be to introduce a synthetic property as
your sort key, and defer its KVO notification (typed in email):
- (void) setName: (NSString*) newName {
name = newName; // add copy/retain/release stuff as necessary for
your memory management model
[self performSelector: @sel (changeSortName) withObject: nil
afterDelay: 0];
}
- (NSString*) sortName {
return name; // or a copy if you want
}
- (void) changeSortName {
[self willChangeValueForKey: @"sortName"];
[self didChangeValueForKey: @"sortName"];
// might want a rearrangeObjects here too, at least for Tiger
}
_______________________________________________
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