Pregunta

I have an NSOutlineView set to work with a datasource. I have no problems displaying my data, except for a small detail: label branches.

I need to display branches in my tree that are there simply as a way of grouping child elements. Say, I have a "Parent" element. Under "Parent" I'll have an expandable element called "Children" and when that is expanded, all the Children are displayed. But the element "Children" is not part of the business logic.

I know that NSOutlineView does not retain the data it displays so I created a constant at the head of my .m file with the "Children" string. The problem is, if my structure includes a lot of parents, the behaviour of the tree becomes erratic, as every time I expand "Children", I am effectively expanding all "Children" in the tree.

So, how can I add an element to the tree, just for labelling purposes, that although it looks the same, is not the same?

¿Fue útil?

Solución

I would suggest that you create a model, internal to your data source, that closely matches the structure of what you want to display in the outline. This has the double advantage of being easy to understand and usually efficient with regards to delegate calls.

For example, your real model might be a list of books but for display purposes you want to group them the first letter of their title (A,B,C...). Within the data source delegate you could create an array of dictionaries with this structure @{@"firstLetter":@"A", @"books":bookArray}.. In the delegate methods you then use this new array as your model.

Of course, you need to manage this internal model but that's usually simple enough.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top