Skip navigation.
 
mlreloading an NSTreeController
FROM : Gerriet M. Denkmann
DATE : Fri Aug 01 15:04:43 2008

I  have myContentArray, bound to the contentArray of an 
NSTreeController. And an OutlineView which has its columns bound to 
the same NSTreeController.

I do [ myContentArray addObject: someObject ] and this is shown in 
the OutlineView.
Everything works very nicely.

- (IBAction)revertDocumentToSaved:(id)sender
{
   NSMutableArray *newContent = [ [ NSMutableArray alloc ] init ];
   [ outlineTreeController setContent: newContent ];
   [ myContentArray release ]; myContentArray = newContent;

   //    now rebuild myContentArray
   NSError *outError;
   [ self readFromURL: [ self fileURL ]  ofType: @"DocumentType" 
error: &outError ];
}

Is this the correct? (At least it seems to work).

But all disclosure triangels are now closed. Is there some way to 
reopen them to the previous state?
I have the strong feeling that I will have to handle this myself. Ok. 
So be it.

   int numberOfRows = [ outlineView numberOfRows ];
   for( int row = 0; row < numberOfRows; row++ )
   {
       id item = [ outlineView itemAtRow: row ];    //    
_NSArrayControllerTreeNode
       BOOL isExpanded = [ outlineView isItemExpanded: item ];
       if (isExpanded)
       {
           NSString *key = [ item valueForKey: @"Key" ]; <--- does not work.
       };
   };

The objects in myContentArray are key value coding-compliant for the 
key Key.

But I get the error message: [<_NSArrayControllerTreeNode 0x3f1fd0> 
valueForUndefinedKey:]: this class is not key value coding-compliant 
for the key Key.

So what can I do to identify the expanded item?

Or should I just forget about the NSTreeController and fill the table 
from a data source?

All this on 10.4.11 Tiger.


Kind regards,

Gerriet.

Related mailsAuthorDate
mlreloading an NSTreeController Gerriet M. Denkman… Aug 1, 15:04
mlRe: reloading an NSTreeController Jonathan Dann Aug 3, 00:51
mlRe: reloading an NSTreeController Gerriet M. Denkman… Aug 3, 05:35
mlRe: reloading an NSTreeController Jonathan Dann Aug 3, 11:53
mlRe: reloading an NSTreeController Gerriet M. Denkman… Aug 4, 15:04
mlRe: reloading an NSTreeController Jonathan Dann Aug 5, 20:21