filling & sorting and NSTableView through bindings
filling & sorting and NSTableView through bindings
- Subject: filling & sorting and NSTableView through bindings
- From: Koen van der Drift <email@hidden>
- Date: Mon, 29 Jan 2007 19:23:34 -0500
Hi,
I recently switched to bindings to populate an NSTableView with the
contents of an NSMutableArray through an NSArrayController. I am
basing my code on the following tutorial from CocoaDevCentral: http://
www.cocoadevcentral.com/articles/000080.php. But in contrast to the
mailbox tutorial, in my app the array is filled all at once after the
user selects a certain action-button. However, nothing appears in the
tableview, although I can see from the scrollbar that the array is
being populated. Now when I click one of the column headers and then
click on the action-button, I see all the items in the NSTableView as
expected. If I then click on a column header to reverse the display
in the table, all lines are empty again, until I click the again
button (re-populating the array) which then indeed shows the items in
reverse.
So after some more searching, I found a possible solution on mmalc's
binding page, called "Batch import into an array, and other mass
changes". Unfortunately so far I haven't been able to get this to
work. That codes looks like this:
(void) addObjectsToEmployeesFromArray: (NSArray *)otherArray
{
if ([otherArray count] > 0)
{
NSRange range = NSMakeRange([self countOfEmployees],
[otherArray count]);
NSIndexSet *indexes = [NSIndexSet
indexSetWithIndexesInRange:range];
[self willChange:NSKeyValueChangeInsertion valuesAtIndexes:
indexes forKey: @"employees"];
[[self employees] addObjectsFromArray:otherArray];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:
indexes forKey: @"employees"];
}
}
I can convert this to my own code, but what I am missing is where the
key @"employees" comes from. Seems to me that the above snippet is
part of a larger code chunk, which is where @"employees" is also
used. How do I get this to work?
Second question, why doesn't the table automatically reverse it's
display when I click on the column header and how can I fix that (ok,
really 2 questions) ?
thanks,
- Koen.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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