1

ここに画像の説明を入力

このリンクから NSOutlineview を参照しました。選択した値に基づいて、すべての値を動的にロードします。ここでは、パスを取得しながら問題を構築します。

同様に、フォルダパス。(例: D:/NewFolder/Test/blah/blah1

同じように、選択した子のフルパスを親から取得する必要があります。画像では、プロジェクトを選択しました。したがって、次のようにパスを取得する必要があります。

/Test/New Folder/Untitled/Project

私のコードは

  - (IBAction) ButtonClick:(id)sender
  {
    self.treeoutlineview.delegate = self;
            self.treeoutlineview.dataSource = self;

                NSString *roots = @"/";
                NSIndexPath *indexPath = nil;
                indexPath = [NSIndexPath indexPathWithIndex:[contents count]];
                TreeNode *node = [[TreeNode alloc] init];
                [node TitleSet:roots];
                [self.treeController insertObject:node atArrangedObjectIndexPath:indexPath];
  }
   - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
    childItem = item;
return childItem;
  }

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
    noofchildren = 0;
return noofchildren;
 }

 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
return YES;
 }
 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
  valueforcolumn = nil; 
 }

- (BOOL)outlineView:(NSOutlineView *)ov shouldSelectItem:(id)item {
{
  rec = @"New Folder|Test|Backup|Project";
   NSArray *arr = [rec componentsSeparatedByString:@"|"];
[loadChildValues removeAllObjects];

NSIndexPath *indexPath = nil;
if (![self.treeController selectionIndexPath])
{
    indexPath = [NSIndexPath indexPathWithIndex:[contents count]];
}
else
{
    if ([[[self.treeController selectedObjects] objectAtIndex:0] isLeaf])
    {
        NSBeep();
        return;
    }

    indexPath = [self.treeController selectionIndexPath];
    indexPath = [indexPath indexPathByAddingIndex:[[[[self.treeController selectedObjects] objectAtIndex:0] children] count]];
}
for (int i = 2; i< [arr count]; i++) {
    [loadChildValues addObject:[arr objectAtIndex:i]];
    TreeNode *node = [[TreeNode alloc] init];
    [node TitleSet:[arr objectAtIndex:i]];
    [self.treeController insertObject:node atArrangedObjectIndexPath:indexPath];
}

}

これを行う方法。任意のボディ pls はこれを解決するのに役立ちます。前もって感謝します。

4

1 に答える 1

1

やったよ。私は次のコードを実行しました。必要に応じて、このコードを使用してください。

最初のステップでは、アイテムのインデックスパスを取得する必要があります

- (IBAction)RefreshTree:(id)sender {
    NSIndexPath *indexPath = nil;
    if (![self.treeController selectionIndexPath]) {
        indexPath = [NSIndexPath indexPathWithIndex:[contents count]];
    }
    else {
        if ([[[self.treeController selectedObjects] objectAtIndex:0] isLeaf]) {
            NSBeep();
            NSIndexPath *selectedfiler_indexPath = [[[self.treeController selectedNodes] objectAtIndex:0] indexPath];
            [self selectValue:selectedfiler_indexPath];
        }
        else
        {
            indexPath = [self.treeController selectionIndexPath];
            [self selectValue:indexPath];
        }
    }
}

- (void) selectValue : (NSIndexPath *) indexpath
{
     NSMutableArray *dummyval = [[NSMutableArray alloc] init];
     NSTreeNode *firstSelectedNode = [[self.treeController selectedNodes] objectAtIndex:0];
     NSString *getsel = [firstSelectedNode representedObject];
    [dummyval addObject:getsel];
    int i = 0;
    NSInteger j = [[firstSelectedNode indexPath]length];
    while (i < j) {
        firstSelectedNode = [firstSelectedNode parentNode];
        if (i < j -1)
        {
            NSString *st = [firstSelectedNode representedObject];
            [dummyval addObject:[NSString stringWithFormat:@"%@",st]];
        }
        i++;
    }

    NSArray *reversedArray = [[dummyval reverseObjectEnumerator] allObjects];
    NSString *ret_path=[reversedArray componentsJoinedByString:@"/"];
    ret_path = [ret_path substringWithRange:NSMakeRange(1, [ret_path length] - 1)];
    NSLog("%@",ret_path);
}

出力は次のとおりです。テスト/新しいフォルダー/無題/プロジェクト

于 2014-10-13T09:47:39.317 に答える