Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the Item from NSOutlineView's Notifications



Seth,

This doesn't answer your question about notifications, but I had to save
both selection and expansion states separately from the regular autosave
stuff as well.  What I did was ignore the notification and use a couple of
methods, one of which is:

- (NSArray*) getExpandedItemsUUIDList
{
  NSMutableArray*   theList = [NSMutableArray array];
  int         x = 0;
  int         numRows = [self numberOfRows];
  
  for (x = 0; x < numRows; x++)
  {
    id  bookmark = [self itemAtRow:x];
    
    if ([self isItemExpanded:bookmark])
      [theList addObject:[bookmark uuid]];
  }
  
  return theList;
}

(Apologies for the formatting; I hope it's readable.)  'self' here is a
subclass of NSOutlineView.  The method returns an array of UUIDs that I can
use find my objects again to re-expand them ([self expandItem]).  I run this
just before closing my window, but you could trigger it at other places
(even that notification).

The one minor gotcha I discovered is this:  If you start with a
fully-collapsed list and try to re-expand, you must expand parents before
children or it won't work.  If you re-expand in the same order as the array
above, it will work.

DSC

> I'm trying to save and restore the collapsed/expanded states of an
> outline view that is part of my document's window (and thus I can't
> use the provided autosave stuff) so I need to get the item object
> from the notifications, like:
> 
> - (void)outlineViewItemDidExpand:(NSNotification *)notification
> 
> But how are you supposed to actually get the item? I used NSLog with
> [notification userInfo] and it prints out that it has a single item
> with {NSObject = blah blah blah}, but the key NSObject doesn't work
> (even though that is clearly shown when printing [[notification
> userInfo] allKeys] and even [[[notification userInfo] allValues]
> objectAtIndex:0] doesn't work because it causes an exception. I've
> Googled, looked on CocoaDev, asked in #macdev on freenode, and looked
> in the list archives on Cocoa Builder. I'm being driven mad!
> 
> This should be ridiculously simple, but nothing I try works and I'm
> feeling ridiculously silly!
> 
> 
> 
> --
> Seth Willits
_________________________________________________________________________
Dan S. Camper                                         Borrowed Time, Inc.
Software Thaumaturge                                   http://www.bti.net
                                                  Toll-Free: 877.451.8939
                                                      Texas: 512.451.8939


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.