0

In Apple's Mail app, in the outline view on the left, an inbox or a folder is shown in hierarchy but the emails in the folder or email is not shown at all.

I would like to reproduce this feature.

I have an outline view connected to a tree controller. Objects (nodes) are added to the tree controller and displayed in the outline view. How can I prevent some objects from appearing? Specifically, I have folder nodes that contain instances of a custom object. Just as in Mail.app, I would like to only display the folder in the outline view and will have the custom objects displayed in another view.

Some controller code as per request; here I am adding nodes to a folderNode that is selected in the outline view:

indexPath = [treeController selectionIndexPath];
indexPath = [indexPath indexPathByAddingIndex:[[[[treeController selectedObjects] objectAtIndex:0] children] count]];//want to insert the new node at the end of the folder node's array of children
    ...
[treeController insertObject:customObjectNode atArrangedObjectIndexPath:indexPath];
NSLog(@"No. of items selected in tree controller/outline view is %i",[[treeController selectedNodes] count]); //if the folderNode is a leaf, this gives 0, i.e. no selection

// if the folderNode is not a leaf, the added child automatically becomes selected by NSOutlineView. In that case I keep its parent selected (the folder) so the next customObjectNode can be added
[self selectParentFromSelection];//however this method will then do nothing because at this point nothing is selected. Now this whole paragraph of code cannot be repeated because nothing is selected so the first line of code doesn't work.
A A
  • 147
  • 1
  • 2
  • 8

1 Answers1

0

Are you using any other tree controllers which need to continue on to the children?

If not, just have the folder nodes return YES to -isLeaf (and nil for the childNodes key).

paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
  • There are no other tree controllers but I am using an array controller to display the custom objects in a table view. Unfortunately, after setting the folder node to be a leaf, when I insert a custom object via the tree controller nothing is selected in the tree controller ([[treeController selectedNodes] count] returns 0). I can't programmatically get anything to be selected. This has broken my code - a custom object can only be added to a folder node after selection in the UI. Also, may you confirm how you would set childNodes to return nil - when I do it, it makes no difference. Thanks Noa. – A A May 21 '12 at 13:58
  • What do you mean by "insert a custom object via the tree controller"? Would you post your controller code? – paulmelnikow May 21 '12 at 16:59
  • Sorry for the confusion, I just mean a node that has information I am trying to display in the table view. To continue the analogy with Mail.app, my "custom objects" are the email messages. I have used the BaseNode.m file from Apple's SourceView example and my folder node inherits from it (@interface FolderNode:BaseNode) as does the node (what I call custom object here) that I put in the folders (@interface customObjectNode:BaseNode). I have posted some relevant code above. Let me know if there's anything else. Thanks again. – A A May 21 '12 at 18:06
  • `[indexPath indexPathByAddingIndex:[[[[treeController selectedObjects] objectAtIndex:0] children] count]]` looks suspect to me, and I definitely wouldn't use `[treeController insertObject ...` any more. The folders are leaf nodes now, so you shouldn't ask them for their children, or ask the tree controller to manipulate their children. Just use the tree controller to get the selected object, and manipulate it directly. – paulmelnikow May 21 '12 at 18:17
  • Thanks Noa, that's worked. Why is `[indexPath indexPathByAddingIndex:[[[[treeController selectedObjects] objectAtIndex:0] children] count]]` suspect? – A A May 23 '12 at 21:44
  • I suppose for the same reason: because you're calling `-children` on a leaf. – paulmelnikow May 24 '12 at 01:49