So how does your tree controller know how to return FilteredItem
instead of Item? I thought you have to return the model class for the
object controller that you set in the nib file. Also, how did you
manage to avoid duplicating subclasses of Item?

I tried a very simple form of filtering on the children method:

- (NSMutableArray *)children
{
    NSAssert( m_guid != nil, @"unexpected nil value for m_children" );

    NSLog(@"m_children %@", m_children);
    NSMutableArray* filteredChildren = [NSMutableArray array];

    NSEnumerator* en = [m_children objectEnumerator];

    MFST_TreeElement* element = nil;
    while ( element = [en nextObject] )
    {
        if( [element enabled] )
        {
            [filteredChildren addObject:element];
        }

    }

    NSLog(@"filteredChildren %@", filteredChildren);

    //return filteredChildren;

    return m_children;
}

TreeElement is a superclass of RuleGroups and RuleElement. RuleGroups
is a non-leaf node, and RuleElement is a leaf node.

So in the code above if I comment-out "return m_children" and
un-comment filteredChildren, the NSTreeController doesn't draw
anything! Both arrays are empty. I find this bizarre behavior. But
running the code as it is returns the unfiltered array(which, in the
end isn't what I want). So I'm a bit unclear as to what to do next.
You used proxies to avoid this problem?

Michael

On Mon, Jun 23, 2008 at 6:09 PM, Jens Alfke <[EMAIL PROTECTED]> wrote:
>
> On 23 Jun '08, at 5:10 PM, Michael Hanna wrote:
>
>> How do I filter-out the contents of an NSTreeController? I saw an
>> example with NSArrayController by overriding the [NSArrayController
>> -arrangeObjects] method, but NSTreeController doesn't have this
>> method.
>
> I asked about this a month or two ago, and the consensus seemed to be that
> there isn't any built-in way to filter the contents of the tree.
>
> I've ended up doing the filtering myself. If we call my regular tree model
> class Item, then I've created a class FilteredItem. This acts as a proxy for
> an Item, but its -children method filters out the children I don't want to
> display, and returns FilteredItem proxies for those I do.
>
> —Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to