How can I get all childs, grandchilds and grandgrandchilds of an selected NSTreeController Object
i have this simplified Model: http://i.imgur.com/EAug3.png
I have these Elements ordered in an NSOutlineView and Controlled by an NSTreeController.
So I created some dummy data:
Folder1 |___ SubFolder1 |___Element1 |___Element2 |___ SubFolder2 |___SubSubFolder1 |___Element3
The Problem is now: How can I get an array that holds Element1, Element2, Element3 if I select Folder1 and that holds Element1 and Element2 if I select Subfolder1?
My first approach was to create a new NSArrayController bound to an custom property of my NSTreeController Object (Ideriv开发者_运维技巧ed a class for that) but that property only called once and not updated anymore after that. My second approach was to write a Fetch Predicate, but I wasnt successfull... :(
Any ideas?
In order to make sure that changes to your structure are reflected in your custom property, you must define a dependency between keys and keypaths (see -keyPathsAffectingValueForKey:). However, because your keypaths are based on dynamic paths, you can't really do it that way, or you'd end up with an ever-growing list of dependencies.
So you have to do it a bit more manually. Every time you change a node in the tree, you will have to send -willChangeValueForKey: and -didChangeValueForKey: messages to your custom tree controller object, and that will trigger a reload of your flattened tree array. Just make sure you actually re-create the array, too. I assume you're walking the tree and flattening it manually.
精彩评论