Re: NSOutlineView search engine
Re: NSOutlineView search engine
- Subject: Re: NSOutlineView search engine
- From: Alex Rice <email@hidden>
- Date: Wed, 22 Jan 2003 08:05:22 -0700
[you probably shouldn't cross post to both cocoa-dev and osx-dev]
On Tuesday, January 21, 2003, at 05:41 PM, Jacques wrote:
In fact exactly like in iTunes, but with a NSOutlineView insteead of a
NSTableView.
If any body has a idea, it will be welcome.
I'm working on this same problem for my app using an NSOutlineView. I'm
not sure if this is the most elegant way, but it works. In my
NSDocument class, or it could be in your Controller class, I added a
method:
-(NSArray *) filteredChildrenOfItem: (NSMutableDictionary *) item;
Where "item" is an item handled by the NSOutlineView. It is coincidence
I'm using NSMutableDictionary for the data source item. It could be
some other class.
filteredChildrenOfItem: does this
1) setup filtering rules (BOOLs) and/or search terms (NSStrings)
2) enumerate through the children of "item", if any
3) test each item against the rules created in 1.
4) add them to a mutable array filteredChildren
5) return filteredChildren
Once filteredChildrenOfItem: is implemented, then in your NSOutlineView
data source methods, call filteredChildrenOfItem: instead of the data
source directly. For instance
- (int)outlineView:(NSOutlineView *)ov
numberOfChildrenOfItem:(id)item
{
NSArray *children = [self filteredChildrenOfItem: item];
return [children count];
}
- (id)outlineView: (NSOutlineView *)ov
child: (int)index
ofItem: (id)item
{
NSArray *children = [self filteredChildrenOfItem: item];
if ([children count] <= index) return nil;
return [children objectAtIndex:index];
}
... etc for all other outlineView: data source methods
This way is actually easier with an outlineview than with tableview
because outlineview handles the items directly and uses the "ofItem:"
methods to access data. Whereas the tableview is always using
index-based access to data source.
Alex Rice <email@hidden> | Mindlube Software |
http://mindlube.com
what a waste of thumbs that are opposable
to make machines that are disposable -Ani DiFranco
_______________________________________________
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.