Skip navigation.
 
mlRe: advice on filtering TreeNode objects
FROM : Mike Shields
DATE : Sun Nov 03 23:28:29 2002

What he's saying is that your data source object - the one that
contains the tree nodes as an ivar - shoudl do the filtering. The
underlying data doesn't change, but the display of them does. So when
the table asks the data source for the number of children/object for
row, etc. run the filter there. For the top level items, the filter
will limit it to just those that should be shown, then the outline view
won't ask for any sub items except for those that are filtered.

Below is some real simple code to illustrate what I'm talking about.
MyFilter is some class/instance of a filter object that can give you a
yes/no answer to whether the item should be shown or not. MyFilter is
where all of the real hard work happens.

- (int)outlineView:(NSOutlineView *)outlineView
numberOfChildrenOfItem:(id)item
{
   int count = 0;
   int idx;
   for (idx = 0; idx < [item children]; idx++)
   {
       if ([MyFilter itemMatchesFilter:[item childAtIndex:idx]] == YES)
           count++;
   }

   return count;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(int)index
ofItem:(id)item
{
   int idx;
   for (idx = 0; idx < [item children]; idx++)
   {
       if ([MyFilter itemMatchesFilter:[item childAtIndex:idx]] == YES)
           index--;
       if (index == 0)
       {
           return [item childAtIndex:idx];
       }
   }

   return nil;
}


Mike
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mladvice on filtering TreeNode objects Alex Rice Nov 3, 09:42
mlRe: advice on filtering TreeNode objects Andreas Mayer Nov 3, 13:33
mlRe: advice on filtering TreeNode objects Alex Rice Nov 3, 22:48
mlRe: advice on filtering TreeNode objects Mike Shields Nov 3, 23:28
mlRe: advice on filtering TreeNode objects Chris Giordano Nov 4, 18:16
mlRe: advice on filtering TreeNode objects Andreas Mayer Nov 5, 05:38
mlRe: advice on filtering TreeNode objects Alex Rice Nov 5, 18:57