Skip navigation.
 
mlRe: Opening column for edit after adding to tree controller?
FROM : Jonathan Dann
DATE : Sat May 31 22:35:16 2008

>
> The problem is, I don't know how to determine to which row that 
> newly-added object corresponds in the table view. Is there any way? 
> I suppose it's the current-selected row, since it's set up to select 
> on add. Is there a more elegant way to find out, though (i.e., what 
> if adding didn't change the selection).
>
> How does one find the row in the table view corresponding to any 
> given instance?
>


Add this to your category on NSTreeController. It calls the -
flattendedNodes method I gave you earlier.  You can then get the tree 
node for the whatever you added to the tree and call NSOutlineView's -
rowForItem:

- (NSTreeNode *)treeNodeForObject:(id)object;
{    
   NSTreeNode *treeNode = nil;
   for (NSTreeNode *node in [self flattenedNodes]) {
       if ([node representedObject] == object) {
           treeNode = node;
           break;
       }
   }
   return treeNode;
}

For those searching the archives, the previous code examples are in 
this thread:

http://lists.apple.com/archives/cocoa-dev//2008/May/msg03138.html

Jon