简体   繁体   中英

Filtering children of NSOutlineView with NSTreeController

I am developing a Mac app which uses Core data. I am using NSOutlineView and NSTreeController to bind data on view.

You can assume the structure of my data as

  • Parent Item 1
    • Child Item 1
    • Child Item 2
    • Child Item 3
  • Parent Item 2
    • Child Item 4
    • Child Item 5

I am applying a fetchPredicate to my NSTreeController to filter the data successfully. On the other hand, the fetchPredicate is applied only to the first level of the data (to parent Items).

I need a method which I can apply a fetchPredicate also to the child items. For example if my criteria matches to Child Item 1 and Child Item 4 the result should be

  • Parent Item 1
    • Child Item 1
  • Parent Item 2
    • Child Item 4

Any help will be appreciated.

You're applying a fetch predicate. NSTreeController doesn't support a filter predicate. NSTreeController uses the fetch predicate to fetch the top level objects and uses the children relationship to get the children. The children aren't fetched and the fetch predicate is not used to get the children.

Solution 1: implement a calculated property filteredChildren , like in this question: Filtering A Tree Controller and mentioned in this unrelated answer: Is it possible to bind an NSTreeController to an NSOutlineViewDataSource?

Solution 2: use a data source instead of bindings, also mentioned in the above answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM