Hoping one of you might have come across this before and can provide
some suggestions:
I have a minimal app with an NSTableView whose NSTableColumns have
"value" bindings to an NSArrayController's arrangedObjects. The
NSArrayController's "content" binding in turn is set to a data array of
objects in my controller class. Then I have the obligatory "Add" and
"Delete" buttons wired to the NSArrayController's corresponding methods.
All this is working fine, I can add and remove table rows no problem,
provided I type the data into the fields myself.
However, if I unarchive the data array from disk, the table isn't
updated to reflect that there is now real content data in my array.
I tried [tableView reloadData] but I believe that's for tables that
work the "old" way using tableView:objectValueForTableColumn:row: etc,
not for bindings.
I also tried sending the "rearrangeObjects" message to the
NSArrayController, but that also doens't cause the display to be
updated.
After a few hours I found the only way to "kick" the
table/arraycontroller combination into redisplaying (and hence
displaying the new data in the data array) was insert a dummy entry in
position 0 and then to remove it again, like this:
[theArrayController insertObject:temp atArrangedObjectIndex:0];
[theArrayController removeObjectAtArrangedObjectIndex:0];
But that feels kind of slimy :-)
Is there a kindler, gentler way to tell the table (or
NSArrayController) that there is new data to be drawn?
Thanks,
Chris
Patrick Machielse - 26 Oct 2005 09:42 GMT
> I have a minimal app with an NSTableView whose NSTableColumns have
> "value" bindings to an NSArrayController's arrangedObjects. The
[quoted text clipped - 7 lines]
> However, if I unarchive the data array from disk, the table isn't
> updated to reflect that there is now real content data in my array.
This should be automatic, provided you trigger the binding mechanism by
using either standard accessors or key-value coding. So in your
'unarchiving code' don't do:
- (void)unarchive
{
[array release];
array = [[NSArray arrayWithContentsOfFile:file] retain];
}
this will change the value of the bound array 'behind the controller's
back', but do
[self setArrray:[NSArray arrayWithContentsOfFile:file]];
or
[self setValue:[NSArray arrayWithContentsOfFile:file]
forKey:"array"];
patrick