Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / October 2005



Tip: Looking for answers? Try searching our database.

Kicking bindings to refresh a NSTableView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doctor Captain - 26 Oct 2005 03:16 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.