开发者

How to find NSOutlineView row index when using NSTreeController

I'm using an NSTreeController to manage nodes for an NSOutlineView. When the user adds a n开发者_Python百科ew 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?)


When you insert a new node it gets selected automatically in the outline view. So you can get the proper row by using...

NSInteger selectedRow = [entityCollectionOutlineView selectedRow];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜