• 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: advice on filtering TreeNode objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: advice on filtering TreeNode objects


  • Subject: Re: advice on filtering TreeNode objects
  • From: Mike Shields <email@hidden>
  • Date: Sun, 3 Nov 2002 15:28:29 -0700

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@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: advice on filtering TreeNode objects (From: Alex Rice <email@hidden>)

  • Prev by Date: Re: MVC and thread-safety
  • Next by Date: Re: MVC and thread-safety
  • Previous by thread: Re: advice on filtering TreeNode objects
  • Next by thread: Re: advice on filtering TreeNode objects
  • Index(es):
    • Date
    • Thread