Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering a NSOutlineView/NSTreeController

How would I use a search box to filter a NSOutlineView/NSTreeController? I know it would have something to do with bindings and a predicate. But not specificaly how to. Could someone take me through the steps of filtering an NSOutlineView/NSTreeController?

like image 856
Joshua Avatar asked Oct 16 '25 14:10

Joshua


2 Answers

I don't think you can. NSArrayController allows you to give it a filter predicate; NSTreeController doesn't. I suggest you file a bug.

like image 102
Peter Hosey Avatar answered Oct 18 '25 14:10

Peter Hosey


As of macOS 10.11, NSTableView (and therefore the subclass NSOutlineView) has new hideRows & unhideRows methods that simplify the task to filtering out rows. There's still no automatic support for filtering out items in NSTreeController (which is not a subclass of NSArrayController, and thus does not inherit its filter predicate), but it at least does a lot of the heavy lifting of allowing you to keep the whole model in the controller while only displaying only a subset of it.

like image 29
marcprux Avatar answered Oct 18 '25 13:10

marcprux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!