• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Implementing NSOutlineView autosaveExpandedItems with CoreData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: WebKit: Javascript - Cocoa bridge not working
  • Next by Date: Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"
  • Previous by thread: WebKit: Javascript - Cocoa bridge not working
  • Next by thread: Where is "Accessibility Reference for Assistive Applications"?
  • Index(es):
    • Date
    • Thread