Re: Implementing NSOutlineView autosaveExpandedItems with CoreData
Re: Implementing NSOutlineView autosaveExpandedItems with CoreData
- Subject: Re: Implementing NSOutlineView autosaveExpandedItems with CoreData
- From: David Hoerl <email@hidden>
- Date: Fri, 03 Apr 2009 22:49:34 -0400
[for the archives - old thread]
This is a brute force mechanism to save the expanded NSOutlineView
items prior to changing a Managed Object context and then restoring
them after the modification.
- (id)expandedState
{
NSMutableArray *state = [NSMutableArray array];
NSInteger count = [outlineView numberOfRows];
for (NSInteger row = 0; row < count; row++) {
id item = [outlineView itemAtRow:row];
if ([outlineView isItemExpanded:item])
{
[state addObject:[item representedObject] ];
}
}
return state;
}
// brute force solution: for each object, do a full tree search for
the NSTreeNode item...at least it works!
-(id)recursiveSearch:(id)object set:(NSSet *)set
{
for (id item in set)
{
if ([item representedObject] == object) return item;
NSSet *children = [item valueForKey:@"childNodes"];
if ([children count]) {
id ret = [self recursiveSearch:object set:children];
if(ret) return ret;
}
}
return nil;
}
- (void)setExpandedState:(id)state
{
// Collapse everything first
[outline collapseItem:nil collapseChildren:YES];
for (id pobj in state) {
[outlineView expandItem:[self recursiveSearch:pobj
set:[[treeController arrangedObjects] valueForKey:@"childNodes"]] ];
}
}
David
_______________________________________________
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