如何在大纲视图中不显示某些节点​​?

时间:2012-05-19 16:27:07

标签: cocoa cocoa-bindings nsoutlineview nstreecontroller

在Apple的Mail应用程序中,在左侧的大纲视图中,收件箱或文件夹以层次结构显示,但文件夹或电子邮件中的电子邮件根本不显示。

我想重现此功能。

我有一个连接到树控制器的大纲视图。对象(节点)将添加到树控制器中并显示在大纲视图中。如何防止出现某些物体?具体来说,我有包含自定义对象实例的文件夹节点。就像在Mail.app中一样,我只想在大纲视图中显示该文件夹,并将自定义对象显示在另一个视图中。

根据请求的一些控制器代码;这里我将节点添加到在大纲视图中选择的folderNode:

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.

1 个答案:

答案 0 :(得分:0)

您是否正在使用任何其他需要继续接触孩子的树控制器?

如果没有,只需让文件夹节点将YES返回到-isLeaf(对于childNodes键,返回nil)。