> On 11 Jun 2015, at 16:22, Gordon Apple <[email protected]> wrote:
>
> If you are going to use a data hierarchy, then use a data hierarchy. Look
> like you are attempting to use a linear array, which won¹t work. You need
> arrays of arrays and you bind the tree controller to the root array.
I don’t think you understood the question or you don’t understand how
NSTreeController works.
Yes, inside the Tree Controller it is stored as array’s of array's, but to add
nodes to the tree, it doesn’t matter how they are stored, my question is how to
find a place in the tree (iow, the Index Path) in which to add a node.
I have a flat list, but there is nothing stopping me adding this to the tree
however I like (except that I’m not sure how to form the Index Path, which is
why I posted). I just want to know if the “ContentArray” can be used to do this
or if I have to use the Tree Controller Selection methods?
There really needs to be more/better documentation on this.
Let me rephrase the question, if I have a tree with the following items in it:
Root --> ContainerA- -> ContainerB —> ContainerC
this would correspond with Index Path 0.0.0.0, so to add to ContainerC, I’d
need an Index Path of:
0.0.0.0.0, which would make the tree look like this:
Root --> ContainerA- -> ContainerB —> ContainerC —> NewItemA
If I were to add another Item to Container C, then it would looking like this:
Root --> ContainerA- -> ContainerB —> ContainerC —> NewItemA Index
Path 0.0.0.0.0
Root --> ContainerA- -> ContainerB —> ContainerC —> NewItemB Index
Path 0.0.0.0.1
----------------------
Given that I have the Tree looks like this:
Root --> ContainerA- -> ContainerB —> ContainerC
If I look in the Content Array, I see:
ContainerA ContainerB ContainerC
Array[0] Count:1 —> Array[0] Count:1 —> Array[0] Count:0
So, to add “NewItemA”, I can scan starting at the Content Array and the index
in the array to form an Index Path, e.g. the insert point of NewItemA is
0.0.0.0 = e.g. the 0th, item cf container C, e.g. the [Array count] is the next
available index in the tree (so if I wanted to add to ContainerB, then the
index path would be 0.1). After adding NewItemA, ContentArray looks like this:
ContainerA ContainerB ContainerC
NewItemA
Array[0] Count:1 —> Array[0] Count:1 —> Array[0] Count:1 —>
NewClassA
After adding NewItemB:
ContainerA ContainerB ContainerC
Array[0] Count:1 —> Array[0] Count:1 —> Array[0] Count:2 —>
NewItemA
Array[1] —> NewItemB
My question is, can I safely use ContentArray is this manner? While searching
for documentation on this I found something that seemed to suggest that this
wasn’t reliable, but from all the reading and experimenting I’ve done, it seems
like it should work, but I’d like to be sure!
The only other way I can see of doing it is to use the NSTreeController
“Selection” Array methods, but these seem slow, and cumbersome to use, since I
think they are designed for use when added items view a UI, not from being
driven by software which the data already having been built.
Cheers
Dave
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]