Re: NSOutlineView autosaving of expanded/collapsed state
Re: NSOutlineView autosaving of expanded/collapsed state
- Subject: Re: NSOutlineView autosaving of expanded/collapsed state
- From: Ralph Manns <email@hidden>
- Date: Sun, 24 Feb 2008 23:45:55 +0100
Am 24.02.2008 um 23:37 schrieb Jonathan Dann:
Hi Ralph,
Here's my code from an NSOutlineView subclass
- (NSArray *)expandedItems;
{
NSMutableArray *expandedItemsArray = [NSMutableArray array];
NSUInteger row, numberOfRows = [self numberOfRows];
for (row = 0 ; row < numberOfRows ; row++)
{
id item = [self itemAtRow:row];
if ([self isItemExpanded:item])
[expandedItemsArray addObject:[item representedObject]]; //
create an array of only the expanded items in the list
}
return [[expandedItemsArray copy] autorelease];
}
The returned array can then be archived.
It uses NSTreeNode and -representedObject, so is 10.5 only. For 10.4
there is an undocumented method for the private class that
NSTreeController used in 10.4 that does the same thing, can't
remember the method name but it's on Scott Stevenson's blog
somewhere, just Google theococoa.com and NSTreeController.
Passing the (now unarchived) array to the method below will expand
them again.
- (void)expandItems:(NSArray *)array;
{
NSUInteger row, numberOfRows = [self numberOfRows];
for (MyNode *savedItem in array) {
for (row = 0 ; row < numberOfRows ; row++) {
id item = [self itemAtRow:row];
MyNode *realObject = [item representedObject];
if ([realObject.nodeName isEqualToString:savedItem.nodeName]) {
[self expandItem:item];
numberOfRows = [self numberOfRows];
break;
}
}
}
}
Enjoy,
Jon
Hi Jon,
thanks for your response and providing your code. Works great.
Ralph.
_______________________________________________
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