1

NSOutlineViewでルート項目のみを展開するという単純な問題を解決しようとしていますが、うまくいきません。すべてのアイテムと選択したアイテムを展開できますが、ルート ノードだけを展開する方法を正確に特定する方法がわかりません。アウトラインビューにはフォルダーのツリーが表示され、ルートフォルダーのすぐ下で使用可能なフォルダーを表示したいのですが、フォルダーの子を展開したくありません。

現在、NSTreeController の selectionIndexPath を設定してから、outlineview で選択を展開しようとしています。

 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];
4

1 に答える 1