• 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: Expand item in NSOutlineView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Expand item in NSOutlineView


  • Subject: Re: Expand item in NSOutlineView
  • From: Conor <email@hidden>
  • Date: Sat, 01 Sep 2007 13:01:02 +0200

This one is a tricky one. Set in awakeFromNib or IB:

[self setAutosaveName:@"MyOutline"];
[self setAutosaveExpandedItems:YES];

Then provide this delegate method so it can save the objects that are
expanded:

- (id)outlineView:(NSOutlineView *)outlineView
persistentObjectForItem:(id)item {
    return [[[[item observedObject] objectID] URIRepresentation]
absoluteString];
}

Then instead of letting it do it alone by providing the opposite delegate
function - (id)outlineView:(NSOutlineView *)outlineView
itemForPersistentObject:(id)object, I wrote my own expand routine and call
it at applicationDidFinishLaunching with:

[outlineView performSelector:@selector(expandURIs:)
withObject:[preferencesStandard objectForKey:@"NSOutlineView Items
MyOutline"] afterDelay:0.0];  //The Autosave name has to match

The expand routine to put into the subclass of NSOutlineView. Here also
watch out, this is my code as is, and it happens that my delegate is also
the subclass, so the call to "[self outlineView:..." should really go to the
delegate if it's a different object.

// Expands the URI for the object given.
// Is recursive if an object is found and others aren't as it might have
been nested inside the one that was found.
- (void)expandURIs:(NSArray *)someURIs {

    //Get items from the preferences
    NSMutableArray *notFoundNested = [NSMutableArray array];
    BOOL foundAtLeastOne = NO;
    NSEnumerator *collectionsToExpandEnum = [someURIs objectEnumerator];
    NSString *nextCollectionURI;

    while (nextCollectionURI = [collectionsToExpandEnum nextObject]) {
        int i, numberOfRows = [self numberOfRows];
        BOOL found = NO;

        for (i = 0; i < numberOfRows; i++ ) {

            if ([[self outlineView:self persistentObjectForItem:[self
itemAtRow:i]] isEqualToString:nextCollectionURI]) {
                [self expandItem:[self itemAtRow:i]];
                foundAtLeastOne = YES;
                found = YES;
                break;
            }
        }

        if (found == NO) {
            [notFoundNested addObject:nextCollectionURI];
        }
    }

    if (foundAtLeastOne && [notFoundNested count])
        [self expandURIs:notFoundNested];
}

Regards,
Conor
http://www.bruji.com/


_______________________________________________

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: Re: creating bookmarks bar.....
  • Next by Date: many messages between threads
  • Previous by thread: Re: Text Animation
  • Next by thread: many messages between threads
  • Index(es):
    • Date
    • Thread