How to find NSOutlineView row index when using NSTreeController

Posted by velocityb0y on Stack Overflow See other posts from Stack Overflow or by velocityb0y
Published on 2010-05-03T06:02:43Z Indexed on 2010/05/03 6:08 UTC
Read the original article Hit count: 340

Filed under:

I'm using an NSTreeController to manage nodes for an NSOutlineView. When the user adds a new item, I create a new object and insert it:

EntityViewEntityNode *newNode = [EntityViewEntityNode nodeWithName:@"New entity" entity:newObject];

// Insert at end of group
//
NSIndexPath *insertAt = [pathOfGroupNode indexPathByAddingIndex:[selected.children count]];
[entityCollectionTreeController insertObject:newNode atArrangedObjectIndexPath:insertAt];

Now I'd like to open the table column for edit so the user can name the new item. This seems logical:

NSInteger row = [entityCollectionOutlineView rowForItem:newNode];
[entityCollectionOutlineView editColumn:0 row:row withEvent:nil select:YES];

However, row is always -1 indicating the object isn't found. Poking around reveals that the tree controller is not actually putting my objects directly in the tree, but is wrapping them in a node object of its own.

Anyone have insight into how I would go about getting a row index relative to the outline view, so I can do this (without, hopefully, enumerating everything in the outline view and figuring out the mapping back to my node?)

© Stack Overflow or respective owner

Related posts about cocoa