我正在尝试解决一个简单的问题,即仅扩展NSOutlineView中的根项目但没有运气。我可以展开所有项目和选定项目,但我似乎无法弄清楚如何准确地确定如何仅扩展根节点。大纲视图显示文件夹树,我想显示根文件夹下可用的文件夹,但我不想展开文件夹子项。
我目前尝试设置我的 NSTreeController 的 selectionIndexPath ,然后在大纲视图中展开选择:
NSIndexPath *indexPath;
NSUInteger section = [indexPath indexAtPosition:0];
NSIndexPath *ip = [NSIndexPath indexPathWithIndex:section];
[outlineView collapseItem:nil collapseChildren:YES];
[self.treeController setSelectionIndexPath:ip];
[outlineView expandItem:[self.treeController selectionIndexPath]];
这不起作用。非常感谢有关如何正确解决此问题的建议。
干杯,特隆德
解决方案: 我已经拥有的和@PaulPatterson 建议的以下组合完美地工作:
[outlineView collapseItem:nil collapseChildren:YES];
NSIndexPath *indexPath;
NSUInteger section = [indexPath indexAtPosition:0];
NSIndexPath *ip = [NSIndexPath indexPathWithIndex:section];
[outlineView collapseItem:nil collapseChildren:YES];
[self.treeController setSelectionIndexPath:ip];
id node = [[self.treeController selectedNodes] firstObject];
[outlineView expandItem:node];